Home »
C programs »
C common errors programs
Error: expected declaration specifies before printf in C
Here, we are going to learn why an error expected declaration specifies before printf() in C occurred and how to fix it in C programming language?
By IncludeHelp Last updated : March 10, 2024
Error: expected declaration specifies before printf
The main cause of this error is - missing opening curly brace ({), before the printf() function.
Example
#include <stdio.h>
int main(void)
printf("Hello world");
return 0;
}
Output
prog.c: In function ‘main’:
prog.c:4:2: error: expected declaration specifiers before ‘printf’
printf("Hello world");
^~~~~~
prog.c:5:2: error: expected declaration specifiers before ‘return’
return 0;
^~~~~~
prog.c:6:1: error: expected declaration specifiers before ‘}’ token
}
^
prog.c:6:1: error: expected ‘{’ at end of input
In this program, opening brace of the main() block is missing
How to fix?
To fix this and such errors, please take care of curly braces, they are properly opened and closed.
Correct Code
#include <stdio.h>
int main(void){
printf("Hello world");
return 0;
}
Output
Hello world
C Common Errors Programs »