what is return 0 in c ?
What is the exact use of return 0 in c programming? When does the 0 goes to or returns to ? What is a calling function? Can some one explain me this with using simple language as I am not familiar with programming?
The statement return 0;
is used to indicate that a C program has completed successfully and is ready to exit. When you write a C program, the main function typically has the following structure:
- int main() {
- // Your program code goes here
- return 0;
- }
The return 0;
statement at the end of the main()
function is used to indicate that the program has executed without any errors. The value 0
is then returned to the operating system or the program that called your C program.
Inside the main function:
- return 0: A return 0 means that the program will execute successfully and did what it was intended to do.
- return 1: A return 1 means that there is some error while executing the program, and it is not performing what it was intended to do.
Inside the user-defined function:
- return 0: returning false from a function.
- return 1: returning true from a function.
Conclusion:
Use-case | return 0 | return 1 |
In the main function | return 0 in the main function means that the program executed successfully. | return 1 in the main function means that the program does not execute successfully and there is some error. |
In user-defined function | return 0 means that the user-defined function is returning false. | return 1 means that the user-defined function is returning true. |
Comments
Post a Comment