ProgrammingHardProduct company OA

What is printed?

What is printed?
printf("%d", 5["abcdef"] - 'a');
  1. A. Compilation error
  2. B. 5
  3. C. 102
  4. D. 6

Correct answer: B. 5

E1[E2] is defined as *(E1 + E2), so 5["abcdef"] is the same as "abcdef"[5], the character 'f'. 'f' − 'a' = 5 because lower-case letters are consecutive in ASCII. 102 is the code of 'f' itself.

More C Programming questions

Exams that ask this topic