0

hi

what is the difference between :

main(){}
void main(){}
int main(){}
int main(void){}

with my best wishes,,

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Aser10
0

In C++ there is only one valid defintion of main and it is
int main()
{
}

or

int main( int argc, char** argv )
{}

A main should return an int. If the return is ommitted as it is here then the compiler will implicitly return 0.

int main(void) will probably be accepted but is frowned upon as being a c-ism.

you should only use the standard conforming
int main(){}
or
int main(int argc, char** argv){}

0

hi

what is the difference between :

main(){}

This version uses an IMPLIED int return value. It is NOT standard and should never be used.

void main(){}

This version declares no return value. It is NOT standard and should never be used.

int main(){}

This version uses an EXPLICIT int return value and should ALWAYS be used, unless you are expecting command line arguments.

int main(void){}

This version is acceptable, but redundant. In C++, you really shouldn't use a "void" parameter for functions that have no arguments. It is NOT advisable to use this version.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.