C Basics · beginner · ~5 min
Know the entry point and what the return value of main means.
Every C program starts at a single function named main. The runtime calls it for you. The return value of main becomes the process exit status — 0 means success, anything else signals a failure to the parent process (shell, init, your CI).
The two standard signatures are int main(void) (no command-line arguments) and int main(int argc, char **argv) (where argc is the count and argv is the array, with argv[0] being the program name).
#include <stdio.h>
int main(int argc, char **argv) {
printf("got %d args; first one is %s\n", argc, argv[0]);
return 0;
}
void main(void) — this is non-standard. Always return int.return 0; at the end (modern C lets you, but be explicit).