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

Discussion

Output?

int main() 
{ 
    char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'}; 
    printf("%s ", **a); 
    return 0; 
} 

 

  • A.Compiler Error
  • B.geeksquiz followed by garbage characters
  • C.geeksquiz
  • D.Runtime Error

Answer: C

Correct answer: geeksquiz

The array is 2×3×3 = 18 bytes in one contiguous block. The nine initialisers fill the first nine, and the remaining bytes are zero-filled, as a partly initialised array always is. **a is the address of the first byte, and %s prints from there to the first null - which is byte 10. So the whole run of nine characters comes out, with no garbage after it.

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

Post your comment

Please log in or register to post a comment.