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 100ConceptIn C, the %c conversion specifier converts an int argument to unsigned char and writes the resulting character from the implementation’s execution…

  1. A.

    prints 100

  2. B.

    prints ASCII equivalent of 100

  3. C.

    prints garbage

  4. 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

  1. The call supplies the integer value 100 to %c.

  2. The official UGC NET key uses the conventional ASCII interpretation of the execution character set.

  3. 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.

Explore the full course: Coding For Placement

Loading lesson…