Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

c++ - 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 << "
";
}

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...