C | String | Question 11

Predict the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
    char str[] = "%d %c", arr[] = "GeeksQuiz";
    printf(str, 0[arr], 2[arr + 3]);
    return 0;
}

chevron_right


(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'.


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.