'expected a type specifier in C
All of my programs before have been working well with C except for today. For some reason I keep getting "expected a type specifier"
I am confused why this is not working.
#include <stdio.h>
printf("Hello World"); // error: expected a type specifer
int test = 90;
printf("%d", test); // same error here: expected a type specifier
// also getting "variable "test" is not a type name"
Solution 1:[1]
You cannot have statements outside of a function in C. That's what is causing the errors you're seeing.
The main function serves at the starting point for a C program, so start by putting the statements in that function.
#include <stdio.h>
int main()
{
printf("Hello World");
int test = 90;
printf("%d", test);
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dbush |
