×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

Error: expected declaration or statement at end of input in C

Here, we will learn why an error expected declaration or statement at end of input is occurred and how to fix it?
By IncludeHelp Last updated : March 10, 2024

Error: expected declaration or statement at end of input

The main cause of this error is – missing closing curly brace (}) of the main() block.

Example

#include <stdio.h>

int main(void){
	printf("Hello world");
	return 0;

Output

prog.c: In function ‘main’:
prog.c:5:2: error: expected declaration or statement at end of input
  return 0;
  ^~~~~~

In this program, closing 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 »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.