Discussion
What will be the output of the program assuming that the array begins at location 1002?
#include <stdio.h>
int main()
{
int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},
{2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
return 0;
}
Answer: C
Correct answer: 1002, 1002, 1002, 1
The first three arguments all denote the same address, differing only in type. a is a pointer to the first two-dimensional sub-array, *a a pointer to its first row, and **a a pointer to its first element - but the first element sits at the start of the first row, which sits at the start of the array, so all three are 1002.
Only ***a dereferences all the way through to a value, giving the first element, 1. This is the standard demonstration that an array's address and its first element's address coincide numerically while differing in type.
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