What is the purpose of returning a value from main () in C / C ++?

Possible duplicates:
The main () function returns a value?
What should main () return to C / C ++?

What is the purpose of returning a value from main () in C and C ++?

How does the return value help us?

Is it possible to use the return value to achieve something important?

+3
source share
5 answers

This is exit status . It is usually used to signal in the OS whether the process was successful or not in what it was doing.

+11
source

Indicates the status of program execution. Usually zero means that it went fine.

+4
source

, , . , , .

. , bash $? . , && || , , , :

# Fetch the images, and only process them if the fetch succeeded (return code 0).
fetch-images && process-images
+3

In a command-line environment, a return value means success or failure in starting the program. This way you can share status information with the caller. Zero is reserved for success on Unix.

+2
source

A more detailed answer can also be found here. More details

+1
source

Source: https://habr.com/ru/post/1789037/


All Articles