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

Showing Answers 1 - 18 of 18 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

Satendra

  • Oct 14th, 2017
 

You can also use main() simply that means same as int main()..
int main() returns an exit value to compiler and works on most compilers.
And getch() as you mentioned has nothing to do with it. It gets character input on screen or else holds screen in other words

  Was this answer useful?  Yes

Mehandi kumari

  • Jan 16th, 2018
 

Void main() doesnt close all the system which is open during program exacution but int main does.

  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.

 

Related Answered Questions

 

Related Open Questions