Discussion
Pick the best statement for the below program snippet:
struct {int a[2];} arr[] = {1,2};
Answer: C
Correct answer: No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
Note the missing inner braces: {1,2} is a flat list, so the values are used to fill the aggregate in order. Both go into the first structure - a[0] = 1 and a[1] = 2 - and nothing is left for a second element, so arr has just one. Writing {{1},{2}} would have given two elements instead.
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