-1

I am unable to understand output of below mentioned program-

#include <stdio.h>

int main()
{
   int i, a[8]={000, 001, 010, 011, 100, 101, 110, 111};

for(i=0;i<8;i++)
{
   printf("%d\t",a[i]);             
}
system("pause");
return 0;

}


OUTPUT -

0 1 8 9 100 101 110 111

Why are the initial four values getting converted here???

Anurag
  • 143
  • 1
  • 9

2 Answers2

4

Any integer literal that starts with a 0 followed by other digits is octal, just like any integer literal starting with 0x or 0X, followed by digits, is hexadecimal. C++14 will add 0b or 0B as a prefix for binary integer literals.

See more on integer literals in C++ here.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
2

If you start a number with a 0 it gets converted to an octal number

0xNumber is hex