Discussion
Pick the best statement for the below program:
#include "stdio.h"
int main()
{
struct {int a[2];} arr[] = {{1},{2}};
printf("%d %d %d %d",arr[0].a[0],arr[0].a[1],arr[1].a[0],arr[1].a[1]);
return 0;
}
Answer: D
Correct answer: No compile error and it’ll print 1 0 2 0
The structure type is defined inline, which is legal, and arr[] takes its length from the initialiser - two elements. Each inner brace initialises one structure, and within it {1} sets a[0] to 1 while the remaining members are zero-filled, as always in a partly initialised aggregate. So the output is 1 0 2 0.
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