Sunday, December 18, 2011

Why main() should not have void as return type ?

Main() is actually defined in the libraries as int main() but not as void main() . This is the main reason we should use it with return type int. Even the ANSI standards suggests us to use int main() . If this is not followed, there is a chance of stack corruption.

Here is a most famous question .. It works fine with void as return type. So why should I go with int ??

it may work sometimes because of the existing garbage values. But no one calls main() in fact, when we execute a program, automatically the predefined callers initiates main() by calling it. This process involves a main() as called function , a shell script and a caller function.

For more detailed answer goto Go4Expert.





If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged

No comments:
Write comments