Printing Integer : %d format specifier : C General Multiple Choice Question



Printing Integer : %d format specifier : C General Multiple Choice Question


What would be the Output of this Program ?

#include<stdio.h>
void main()
{
printf("%d%d%d",50,050,0x50);
}

[toggle title=”Output”]50 40 80[/toggle]


Why ?

  1. %d format specifier is used for Integer
  2. Any number preceded with Zero (040,050,030) are considered as Octal Numbers
  3. Any number preceded with [ 0x / 0X ] (0x40,0x50,0x30) are considered as Hexadecimal Numbers
  4. So Before Printing these numbers Octal & Hex numbers are converted into Decimal Numbers So Output is  50 40 80