为什么以下代码片段中的050
不等于50
?
#include <stdio.h>
int main(void) {
int x=050,y=50;
int ans;
ans= x==y ? x+3 : y+7;
printf("%d\n",ans);
}
最佳答案
因为 050
被视为八进制,而 50
被视为十进制。
因此,x = 050
基本上意味着 x = 40
。
6.4.4.1/3
A decimal constant begins with a nonzero digit and consists of a sequence of decimal digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7 only.
关于c - 为什么以下代码片段中的 050 不等于 50?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58965260/