Register
 

Live Chat for CSC Scholarship 2020

Engineering Education Forum



Author Topic: The program fragment int i = 263; putchar(i);  (Read 1223 times)

Online mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 3125
    • View Profile
    • Engineering Forum
The program fragment int i = 263; putchar(i);
« on: February 28, 2017, 07:06:51 AM »
Advertisement
Question: The program fragment

int i = 263;
putchar(i);


Options are:


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

Correct answer is:

C. rings the bell



Explanation:

263 in binary form is 100000111. If one tries to print an integer as a character. only the last 8 bits will be considered - the rest chopped off. so, in this case the ASCII value of 00000111 (i.e. decimal 7) will be printed. look in the ASCII table. It is ringing the bell!

Engineering Education Forum

The program fragment int i = 263; putchar(i);
« on: February 28, 2017, 07:06:51 AM »