G-Fact 16

Predict the output of following program.

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main() 
{
   int x = 012;
   printf("%d",  x);
   getchar();
   return 0;
}

chevron_right


The program prints 10. Putting a 0 before an integer constant makes it an octal number and putting 0x (or 0X) makes it a hexadecimal number. It is easy to put a 0 by accident, or as a habit. The mistake is very common with beginners.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.