Click here to Skip to main content
16,020,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In C language
1.what is the difference between int main and int main(void) ?
2.why do we use return 0 at the end of the code ?

What I have tried:

searched in google but didn't get any clear explanation.
Posted
Updated 16-Jun-21 20:17pm

See, for instance Main function - cppreference.com[^].
 
Share this answer
 
1. 'int main' defines an integer variable called 'main'. 'int main(void)' defines a function that accepts no parameters and returns an integer.

2. In Unix / Linux / DOS / Windows, the return value from the 'main()' function is traditionally returned as the "exit code" from the program. It is a means of telling the operating system whether the program succeeded. If the program is run in a script / batch file / command file, the script may use this "exit code" to select different actions.

The only three values defined by the C Standard are 0, which traditionally means "success", EXIT_SUCCESS, and EXIT_FAILURE. The last two values are defined in <stdlib.h>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900