Why we use return 0 in our program.|| Why use return 0 in c program.

Short answer

Execution starts from the main () function of the code when we write code in C language. The main () function is declared as follows:

int main ()
Then the compiler expects that the function will return an integer return when the execution ends. That is to say, we have to return one of the integers at the end of the function. 0 is used in conventional rules, to show that the program is going well without any problems. But there is no such thing as to return that 0. Any integers can be returned if you want.

Detailed answer

C language
According to the ISO / IEC 9899: 1989 (C90) standard policy, the main () function can be declared in the following three ways.

int main (void)
int main (int argc, char ** argv)
int main (int argc, char * argv [])
Where the second and third lines are equivalent. The second or third is used to input input from the command line.

The ideal policy about returns is that a program can return three types of values,

0
EXIT_SUCCESS
EXIT_FAILURE
Where the second and third values ​​are #define in the stdlib.h file.

ISO / IEC 9899: 1999 (C99) The standard set of conditions that have been laid down are:

The int word must be specified in the declaration of the main () function. In other words, write main () and enter int main ().
The return 0 can be excluded if you want it. If this line is not written by the main () function execution will be returned 0 by default.
If we do not want to return anything, then we can use void main instead of int main. But using int main () is more supported and encouraged.

C ++ Language

The three main () functions can be declared as C ++ Language C99.

int main (void)
int main (int argc, char ** argv)
int main (int argc, char * argv [])
Using standard void main () in C ++ is absolutely prohibited, that is, the main () function must return the integer, otherwise the code will not be compiled.

Now the question is, what is the need to return something to the function (main)?
When we run the program by writing a code, we command the operating system and run the operating system program. When the execution of the program ends, the value will return to the operating system. 0 indicates that the program is running correctly. No matter how much the program returns, why do not we run the program through operating systems or any command line, it is not important. What is important to know is whether the program has finished correctly. The ideal rule is,

The program returns exactly 0 returns, and then
If the program stops midway between an error (memory overflow or addressing error or any error) during the program, return any value other than 0.
Again, some returned values ​​may be important. Suppose, I have done a program that runs ten child programs on different threads. In that case, there may be a need for decision-making or logical implications based on the value of which process a thread reaches. Again, we can take different return values ​​to #define in case of different errors in the field. So, we can decide from the program's parent program, if the program is going well and if it does not go well then where exactly is the error.