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;
}
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development