Reading the return value of main() on the terminal#
For example, compile and run the following:
int main() { return 42; }
42 becomes the exit code of the program. It is typically interpreted by the terminal as an error code, if the number is greater than 0. If the program ran successfully, it must return 0.
If we avoid the return, then main automatically returns 0.
echo $?
$LASTEXITCODE
You should see as output:
42
