return and exit(0) for Program Termination
For Complete YouTube Video: Click Here
In this class, we will understand return and exit(0) for Program Termination.
We have discussed the concept of return in our previous class.
In this class, we will understand the use of return from a different perspective.
Table of Contents
return and exit(0)
In our previous discussions, we have seen that we will come out of the function whenever a return statement is executed.
If the return statement is executed in the main function, the compiler will terminate the program.
What if we want our program to be terminated at any point in the program.
C compiler provides the facility of program termination by using the exit(0) function.
exit(0) Example
The image below is the programming example to understand the exit(0) function.
The exit(0) is used in the sum function.
With the execution of the exit(0) function, the compiler will terminate the program.
If we run the program, we will not get any output because the sum function will not return the value to the called ‘function.’
Instead, it will execute the exit(0), and the program will get terminated.