What is the output after the execution of the following for loop??

#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\n",a[i]);    
}

A)0,1,2,3,4,5,6,7     B)0,1,10,11,100,101,110,110     C)0,1,8,9,100,101,110,111     D)None of these

 

The answer is C ,could anyone give an explantion regarding why we will get C as answer

1Comment
Habib Mohammad Khan @habibkhan
26 Jul 2017 09:18 pm

When we prefix a '0' before a number , the number is interpretted as in octal system..So 000 would be interpreted as octal equivalent of '00' = 0 , 001 would be interpretted as octal equivalent of '01' = 1 , 010 would be interpretted as  as octal equivalent of '10' = 8 and 011  would be interpretted as  as octal equivalent of '11' = 9..

Hence C) is the correct answer..