A C program starts execution from the main() function. This basic program demonstrates the standard structure of a C program, including a header file, the main() function, a statement, and the return statement.
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
Example Output #
Hello, World!
Explanation #
The header file:
#include <stdio.h>
provides the declaration of printf(), which is used to write formatted output to the standard output stream.
The program entry point is:
int main()
main() returns an int value to the environment that started the program.
The output statement is:
printf("Hello, World!\n");
printf() writes the specified text to standard output. The escape sequence \n moves the output position to the next line.
The statement:
return 0;
terminates main() and returns 0, conventionally indicating successful program termination.
The braces { and } define the body of the main() function, while the semicolon ; terminates each statement.