#include <stdio.h>
#include <stdlib.h>
#define SIZEOF(arr) (sizeof(arr) / sizeof(arr[0]))
#define PrintInt(expr) printf("%s:%d\n",#expr,(expr))
int main()
{
/* The powers of 10 */
int pot[] = {
0001,
0010,
0100,
1000
};
int i;
for(i=0;i<SIZEOF(pot);i++)
PrintInt(pot[i]);
return 0;
}
下面代码的输出是
pot[i]:1
pot[i]:8
pot[i]:64
pot[i]:1000
为什么会给出这样的输出??`
最佳答案
在 C 语言中用 0 数字作为前缀将以八进制输出它,这是一个以 8 为基数的数字系统。
十月(1) = 十二月(1)
十月(10) = 十二月(8)
十月(100) = 十二月(64)
这就是您的数字的来源。
仅供引用,十六进制文字以 0x 为前缀,二进制文字以 0b (IIRC) 为前缀
编辑:要真正回答您的问题,只需从数字中删除前导零,它应该会为您提供所需的输出。
关于c - 10的幂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25208682/