Machine-translated by Google. Questions are authored in English.
Top

Discussion

The program fragment
int i = 263 ;
putchar (i) ;
prints

  • A.263
  • B.ASCII equivalent of 263
  • C.rings the bell
  • D.garbage

Answer: C

Correct answer: rings the bell

putchar takes an int but converts it to unsigned char before writing, so only the low-order byte survives:

\[ 263 \bmod 256 = 7 \]

Character code 7 is BEL, the alert character, so the terminal sounds its bell rather than printing anything. The lesson is general: passing a value outside the range of unsigned char to putchar is not an error but a silent truncation, and the character actually written is whatever the low byte encodes.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.