I'm creating a presentation on how to program in C, and since I'm fairly new to C, I want to check whether my assumptions are correct, and what am I missing.
Every C program has to have an entry point for the OS to know where to begin execution. This is defined by the main() function. This function always has a return value, whether it be user defined or an implicit return 0;.
Since this function is returning something, we must define the type of the thing it returns.
This is where my understand starts to get hazy...
- Why does the entry point needs to have a return value?
- Why does it have to be an
int? - What does the OS do with the address of
int main()after the program executes? - What happens in that address when say a
segfaultor some other error halts the program without reaching areturnstatement?