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

Discussion

Predict the output of below code:

int main() 
{ 
    char a[2][3][3] = {'g','e','e','k','s','f','o', 
                           'r','g','e','e','k','s'}; 
    printf("%s ", **a); 
    getchar(); 
    return 0; 
} 

 

  • A.Geeks
  • B.Error
  • C.geeksforgeeks
  • D.No Output

Answer: C

Correct answer: geeksforgeeks

a is char[2][3][3] - 18 bytes in one contiguous block. The 13 characters of the initialiser fill it in order and the remaining 5 bytes are set to zero, because a partly initialised array has the rest zero-filled. **a is the address of the first byte, and %s prints from there to the first NUL - which is byte 14. So the whole run of 13 characters comes out: geeksforgeeks.

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

Post your comment

Please log in or register to post a comment.