GeekInterview.com
Series: Subject: Topic:
Question: 229 of 589

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

Asked by: Interview Candidate | Asked on: May 1st, 2007
Showing Answers 1 - 4 of 4 Answers
gauravpparikh

Answered On : May 10th, 2007

View all answers by gauravpparikh

every function has a default return type as int .. void main () ensures that the main function does nto return anything

Yes  1 User has rated as useful.
  
Login to rate this answer.

program contain statement main it consider as int main .should return a value. void means null

Yes  1 User has rated as useful.
  
Login to rate this answer.
kbjarnason

Answered On : Jul 1st, 2010

View all answers by kbjarnason

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.

  
Login to rate this answer.

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.