ProgrammingHardTCS NQT · Product company OA

Assume ASCII. What is printed?

Assume ASCII. What is printed?
const char *s = "pointer";
printf("%c%c%c", *s + 1, s[*s - 'o' + 2], *(s + strlen(s) - 1) - 1);
  1. A. qiq
  2. B. qnr
  3. C. pnr
  4. D. qnq

Correct answer: D. qnq

*s + 1 adds 1 to the character 'p', giving 'q' (not the next character of the string). *s − 'o' = 1, so the index is 3 and s[3] = 'n'. The last character is 'r', and 'r' − 1 = 'q'.

More C Programming questions

Exams that ask this topic