ProgrammingHardTCS NQT · Infosys
char msg[] = "abc"; printf("%c", msg[msg[0] - 'a' + 1]); What is printed?
- A. a
- B. b
- C. c
- D. d
Correct answer: B. b
msg[0] is 'a', so 'a' - 'a' + 1 is 1, and msg[1] is 'b'. The character constants are used as integers, which is well defined.
More C Programming questions
- for (int i = 0; i < 10; i++) for (int j = 1; j < 10; j = 2) count++; How many times does count increase?
- What does printf("%d %d", 17 / 5, 17 % 5) print?
- int x = 0; if (x = 5) printf("y"); else printf("n"); What is printed?
- Which expression clears the lowest three bits of an unsigned char x?
- uint32t x = 0u; x -= 1; x = x / 2 + 1; What is x?
- int a[5]; int p = &a[4]; printf("%td", p - &a[0]); What is printed?