What is difference between main() and void main()?

Showing Answers 1 - 4 of 4 Answers

kbjarnason

  • Jul 1st, 2010
 

The short answer is that void main() has never been a legitimate usage in C, and a compiler, seeing it, is well within its rights to spew an error, or worse, spew garbage results if you use it.

By contrast, main() is used to denote a main function which takes no arguments and returns an int, under the implicit int rule.

Better is to be explicit:

int main(void) or
int main(int argc, char *argv[] )

In no case, anywhere, ever, with the sole possible exception of some freestanding implementations, is void main a legitimate construct.  If your compiler accepts it without at least a warning, you should consider a better compiler.

  Was this answer useful?  Yes

The programms under the main() function means that this main() function is of int type as any function is declared as int by default in c language.it means it will return the value which it takes and work upon but the case is not the same with void main() because what we see here that it has benn declared under void return type,it means it will not return any thing

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions