C | String | Question 11
Predict the output of the following program:
#include <stdio.h> int main() { char str[] = "%d %c" , arr[] = "GeeksQuiz" ; printf (str, 0[arr], 2[arr + 3]); return 0; } |
(A) G Q
(B) 71 81
(C) 71 Q
(D) Compile-time error
Answer: (C)
Explanation:
The statement printf(str, 0[arr], 2[arr + 3]); boils down to: printf("%d %c, 0["GeeksQUiz"], 2["GeeksQUiz" + 3]); Which is further interpreted as: printf("%d %c, *(0 + "GeeksQUiz"), *(2 + "GeeksQUiz" + 3)); Which prints the ascii value of 'G' and character 'Q'.