Where does the value of return() goes when we use it in main function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where does the value of return() goes when we use it in main function?

hi all! I am a student and have recently studied Java . in Java we use return function in any function and it's value goes to the function in which we call function having return statement.but in c++ I am studying I have seen codes where return statement was given in main function. we don't need to call main function so where does the value of return goes.?

14th Aug 2017, 2:39 AM
Harsh Wellengsly
Harsh Wellengsly - avatar
3 Answers
+ 11
The value 0 is returned to the caller of your main function, that is, your operating system (as in C/C++) to signal program termination status.
14th Aug 2017, 3:06 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Generally when a main function returns 0; It just means that the program has completed correctly. It doesn't really "go" anywhere, it just completes the execution.
14th Aug 2017, 2:55 AM
S C
+ 1
The return type of the main function tells the caller whether the program exits successfully or not (also known as exit code). For Java, the main was called via the JVM (Java Virtual Machine) in order to run the program.
14th Aug 2017, 2:59 AM
Zephyr Koo
Zephyr Koo - avatar