【发布时间】:2018-12-05 19:40:08
【问题描述】:
我想知道为什么输出中的结果是 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]);
}
【问题讨论】:
-
在数字前加 0 使其成为八进制常数:msdn.microsoft.com/en-us/library/00a1awxf.aspx (010 (base 8) = 8 (base 10))
-
它是标准的——因此无论操作系统或编译器如何,它都可以正常工作。
标签: c++ arrays binary int digit