我想知道为什么输出的结果是 100、8、1。 010 甚至没有任何意义,它不是二进制数字中的 2。我错过了什么吗?
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int code[3];
code[0] = 100;
code[1] = 010;
code[2] = 001;
printf("%d\n", code[0]);
printf("%d\n", code[1]);
printf("%d\n", code[2]);
}
最佳答案
100、010 和 001 不是二进制文字。 100 是十进制字面量; 010 和 001 是八进制(基数 8)文字。如果您使用的是 gcc,则可以通过使用前缀 0b
来支持二进制文字的扩展,如
code[0] = 0b100; // evaluates to 4
关于c++ - 关于二进制数字的 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51053804/