1

Why would printf("%c ", 2293552); print 0?

ASCII values are from 0 to 127 I know this must be some cyclic thing but I want a clear explanation. Thank you

bad_keypoints
  • 1,382
  • 2
  • 23
  • 45

2 Answers2

3

The number 2293552 corresponds to 0x22ff30. When printf interprets it as ASCII, it ignores all bits beyond the last eight bits containing 0x30, which is the code for '0'.

From the C99 standard:

7.19.1.6.8 -- %c: If no l length modifier is present, the int argument is converted to an unsigned char, and the resulting character is written.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

Likely %c is using only the low-order byte of your argument, which is 2293552 & 255 = 48 = '0'.

Keith Randall
  • 22,985
  • 2
  • 35
  • 54