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

跟風遠走 提交于 2019-11-30 15:00:43

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

Lambert already explained that. So let me tell you what else you can do.

You can write hexadecimal integer:

int main() {
    int i = 0x101; //0x specifies this (i.e 101) is hexadecimal integer
    std::cout << i << "\n"; //prints 257 (1 * 16 * 16 + 1)
}

Output:

257
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!