hi

what is the difference between :

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

with my best wishes,,

Recommended Answers

All 3 Replies

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){}

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.

thanx brother

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.