If you really want to understand ANSI C 89, I need to correct you in one thing;
In ANSI C 89 the difference between the following functions:
int main()
int main(void)
int main(int argc, char* argv[])
is:
int main()
- a function that expects unknown number of arguments of unknown types. Returns an integer representing the application software status.
int main(void)
- a function that expects no arguments. Returns an integer representing the application software status.
int main(int argc, char * argv[])
- a function that expects argc number of arguments and argv[] arguments. Returns an integer representing the application software status.
About when using each of the functions
int main(void)
- you need to use this function when your program needs no initial parameters to run/ load (parameters received from the OS - out of the program it self).
int main(int argc, char * argv[])
- you need to use this function when your program needs initial parameters to load (parameters received from the OS - out of the program it self).
About void main()
In ANSI C 89, when using void main
and compiling the project AS -ansi -pedantic
(in Ubuntu, e.g)
you will receive a warning indicating that your main function is of type void and not of type int, but you will be able to run the project.
Most C developers tend to use int main()
on all of its variants, though void main()
will also compile.
void main()
is useful mainly as an indication that you're using a textbook written by someone who doesn't know the C language very well. Of the forms you listed, onlyint main(void)
is valid. (It's not quite that simple, but that's close enough for now.) – Pardoner