Open In App

GFact | Putting a 0 before an integer constant

Improve
Improve
Like Article
Like
Save
Share
Report

Predict the output of following program.




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


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.


Last Updated : 17 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads