ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
char *s = "hello";
printf("%c %c %c", s[1], 4[s], *("abc" + 2));
  1. A. h l c
  2. B. e o c
  3. C. e o b
  4. D. e l c

Correct answer: B. e o c

s[1] is 'e'. Because a[i] is defined as *(a + i), 4[s] means *(4 + s) = s[4] = 'o'. A string literal decays to a pointer, so "abc" + 2 points to 'c'.

More C Programming questions

Exams that ask this topic