ProgrammingModerateTCS NQT · Infosys

What is printed? Assume ASCII character encoding.

What is printed? Assume ASCII character encoding.
#include <stdio.h>
int main(void) {
    int d = 'z' - 'a';
    char e = 'A' + d * 2;
    printf("%d %c", d, e);
}
  1. A. 25 t
  2. B. 26 t
  3. C. 25 s
  4. D. 24 r

Correct answer: C. 25 s

'z' - 'a' is 25, and 'A' + 50 is 115, which is the ASCII code for s. Using the lowercase base instead of the uppercase one gives a different letter.

More C Programming questions

Exams that ask this topic