What are the valid signatures for C’s main() function – int main() or void main() ?

Neither main() or void main() are standard C. The former is allowed as it has an implicit intreturn value, making it the same as int main(). The purpose of main’s return value is to return an exit status to the operating system.

The current C standard C11 valid signatures for main are:

int main(void)

int main(int argc, char **argv)

The form you’re using: int main() is an old style declaration that indicates main takes an unspecified number of arguments. Don’t use it – choose one of those above.

Exit Status:

The exit status or return code of a process in computer programming is a small number passed from a child process (or callee) to a parent process (or caller) when it has finished executing a specific procedure or delegated task. In DOS, this may be referred to as an errorlevel.

The C programming language allows programs exiting or returning from the main function to signal success or failure by returning an integer, or returning the macros EXIT_SUCCESS and EXIT_FAILURE. On Unix-like systems these are equal to 0 and 1 respectively.

Follow Innovation Begins Here on Twitter,Facebook , Google+ &Linkdin.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s