I am a beginner in C language. Can anyone explain in detail using example how main(),int main(), void main(), main(void), void main(void), int main(void) work in C language? As in what is happeneing when we use void main() and what is happening when i use int main() in simple language and so on.
I know but cant understand what is it doing:
when i write simple hello world using the int main() return 0 it still gives me the same output as when using void main()) so how does it work? What is its application?
Neither main()
or void main()
are standard C. The former is allowed as it has an implicit int
return value, making it the same as int main()
. The purpose of main
's return value is to return an exit status to the operating system.
In standard C, the only valid signatures for main
are:
int main(void)
and
int main(int argc, char **argv)
The form you're using: int main()
is an old style declaration that indicates main
takes an unspecified number of arguments. Don't use it - choose one of those above.