ProgrammingHardAccenture · Capgemini

Assume ASCII. What is printed?

Assume ASCII. What is printed?
char s[] = "aB3";
for (char *p = s; *p; p++)
    *p ^= 32;
printf("%d %d %d", s[0], s[1], s[2]);
  1. A. 97 66 51
  2. B. 65 98 19
  3. C. 65 98 51
  4. D. 65 98 83

Correct answer: B. 65 98 19

XOR with 32 flips bit 5. For letters that swaps case: 'a' (97) → 65, 'B' (66) → 98. It is not a case operation, though: it flips the digit '3' (51) too, giving 19. '51' assumes digits are left alone; '83' adds 32 instead of flipping the bit.

More C Programming questions

Exams that ask this topic