0

Consider this code:

int main() { return 10'000; }

I compile it and run it:

$ g++ main.cpp -o p
$ ./p
$ echo $?
16

Why the output of $? is 16? I also tried with Online Compiler too:

And the process return value is 16. What I'm missing?


My environment:

  • OS: Arch Linux x86_64 Linux 5.13.10
  • Compiler: GCC 11.1.0
  • Compiler Additional Flags: -Wall -Wextra -Wpedantic
Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32
  • 3
    Does this answer your question? [Return value range of the main function](https://stackoverflow.com/questions/5149228/return-value-range-of-the-main-function) – Lala5th Aug 22 '21 at 14:25
  • 1
    https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html – 273K Aug 22 '21 at 14:29
  • To support the propsed duplicate: The binary representation of `10'000` is `0010011100010000` if you take the 8 lower bits you have `00010000` which is 16. – Lukas-T Aug 22 '21 at 14:29

0 Answers0