What is the output of the following C statement? printf("%c", 100);
2012
What is the output of the following C statement?
printf("%c", 100);Answer: B. prints ASCII equivalent of 100 — ConceptIn C, the %c conversion specifier converts an int argument to unsigned char and writes the resulting character from the implementation’s execution…
- A.
prints 100
- B.
prints ASCII equivalent of 100
- C.
prints garbage
- D.
none of the above
Attempted by 3 students.
Show answer & explanation
Correct answer: B
Concept
In C, the %c conversion specifier converts an int argument to unsigned char and writes the resulting character from the implementation’s execution character set. The C standard defines this conversion but does not require that character set to be ASCII.
Application
The call supplies the integer value 100 to %c.
The official UGC NET key uses the conventional ASCII interpretation of the execution character set.
In ASCII, character code 100 maps to the lowercase letter d; therefore the statement prints the ASCII character corresponding to 100.
Cross-check
Using %d with the same argument would print the decimal digits 100, whereas %c emits one character. On a non-ASCII execution character set, code 100 need not denote d, so that letter is conditional on ASCII; the official exam key nevertheless makes the ASCII-equivalent description the canonical offered answer.