Register
 

Free CSC Scholarship support for 2018-19

Engineering, Computer, Scholarship and SEO Support Forum



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

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2985
    • 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, Computer, Scholarship and SEO Support Forum

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