+ 1

What does this mean: The line return 0; terminates the main() function and causes it to return the value 0 to the calling proces

25th Oct 2017, 4:15 PM
BLAQking
BLAQking - avatar
4 Antworten
+ 4
The return value of main() defines the error code. For example, 0 means program finished with success.
25th Oct 2017, 6:18 PM
Freezemage
Freezemage - avatar
+ 2
Every running program has a process, and each process manages at least one thread, when a program ceased its operations, its process is terminated, FYI a process can invoke or execute another process (program), and by using a certain mechanism, can "wait" for an value (a termination status) from the child process it executed/invoked. The "return" statement in main function passes the termination status value to the invoking process, which can use it to verify whether or not the invoked process ended with success or failure. The meaning of the number passed back by "return" statement varies between operating systems, but as a general rule, passing back zero indicates a successful operation. Unless it is a fatal unhandled exception that leads to a crash, a coder can opt to terminate the process with a return value that has a meaning, either for the process itself or, both the process and the invoking process (the parent process). Hth, cmiiw
25th Oct 2017, 7:08 PM
Ipang
+ 1
Well, since the access point of the program, the main method must return an integer, yes, it is necessary to return an integer, zero indicates that the program ended successfully. When your program ends it shows you in the console the return, if your program crashed the number will be different from zero, and each number has an error message associated for debugging purposes
1st Feb 2019, 11:13 AM
AnkitKunwar
AnkitKunwar - avatar
0
Fgg
3rd Mar 2022, 1:55 PM
Rocky Arjun