Search code examples
c++octal

What does an extra 0 in front of an int value mean?


Inspiring from a obfuscated piece of code, I have a small question regarding to assign value to an integer:

#include <iostream>
#include <cstdio>

int main() {
    int i = 0101;
    std::cout << i << "\n";
}

And the output was 65, and I have no idea where 65 came from? Any idea?


Solution

  • It specifies an octal (base-8) number: 0101 == 1 * (8 * 8) + 1 == 65.