10的权力

1 c

  #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;
  }
Run Code Online (Sandbox Code Playgroud)

以下代码的输出是

pot [i]:1
pot [i]:8
pot [i]:64
pot [i]:1000

为什么它会给出这样的输出?`

E. *_*fat 9

在C中用0位数字加上数字文字将以八进制形式输出,这是一个基数为8的数字系统.

十月(1)=十二月(1)

十月(10)=十二月(8)

十月(100)=十二月(64)

这就是你的数字来自哪里.

仅供参考,十六进制文字的前缀为0x,二进制文字的前缀为0b(IIRC)

编辑:要实际回答您的问题,只需从数字中删除前导零,它应该为您提供所需的输出.

  • 二进制文字的`0b`是非标准的.(有趣的是,`0`是八进制文字;没有十进制整数文字,其值为零.) (4认同)