Why is the return value different?

I compiled two simple programs in C ++, using minor changes in each of them, and used the query echo $?to output the value returned by the OS by default.

Program 1

    int main()
    {
          return 0 ; 
    }

Program 2

   int main()
   {
       return -1 ; 
   }

When I launched the first program and did echo $?, the value was as expected 0, but when I launched the second program and did echo $?, the value was 255 instead of the expected -1.
Why is this so?
I use Ubuntu 12.04 LTS in case it matters

+4
source share
2 answers

From the POSIX specification forexit() :

0, EXIT_SUCCESS, EXIT_FAILURE , 8 ( 0377).

C:

, ;

+4

Linux . , . , .

+1

All Articles