Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

Correct answer: 71 Q

Both subscripts are written backwards, which is legal: 0[arr] is arr[0] = 'G', and 2[arr+3] is *(arr+3+2) = arr[5] = 'Q'. The format string, itself held in an array, prints the first with %d - giving the character code 71 - and the second with %c, giving Q.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.