ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int main(void) {
    char ch = 'A';
    int code = ch + 1;
    printf("%d %c", code, (char)code);
}
  1. A. 65 A
  2. B. 66 A
  3. C. 65 B
  4. D. 66 B

Correct answer: D. 66 B

ch promotes to int for the addition: 'A' is 65, +1 = 66. Printed as %d, that's 66; cast back to char and printed as %c, 66 is the character 'B'.

More C Programming questions

Exams that ask this topic