Skip to content
Related Articles

Related Articles

Improve Article

C | String | Question 11

  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021
Geek Week

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


Quiz of this Question

Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
My Personal Notes arrow_drop_up
Recommended Articles
Page :