Every C program needs an entry point: main. The simplest program prints a line and returns an exit status to the operating system.
Minimal program
#include <stdio.h>
int main(void) {
printf("Hello, World\n");
return 0;
}
#include <stdio.h> pulls in declarations for printf. return 0; signals success to the shell.
Reading main
int main(void)— takes no arguments (playground default)int main(int argc, char *argv[])— receives command-line arguments (covered later)- Return type
intis the process exit code
Important interview questions and answers
- Q: Why include stdio.h?
A: The compiler needs prototypes forprintf; without it, you may get implicit declaration warnings or errors under modern standards. - Q: What does return 0 mean?
A: Conventionally success; non-zero indicates an error code to the shell.
Self-check
- Which header declares printf?
- What return value means success?
Interview prep
- Why include stdio.h?
Provides the prototype for
printf; modern compilers require declared functions before use.- What does return 0 mean?
Conventionally signals successful program termination to the operating system shell.