You are here:

C/int main(void)

Advertisement


Question
Hi,

This is kind of an odd q.
do you know why the void should be written in the declaration of main ?
(of course "int main() will also work, but it seems more corect to write "int main(void)" do you know why ?

Thanks,
motty.  

Answer
According to ANSI standards, it is int main().
The reason for this is, main() function has to return an integer value as status to the calling program.
In the calling program, it would have been called like this:
int status = main();

So, if you define main() to return void, then the calling program will have problem!

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.