Discussion
What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include <stdio.h>
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf("%u, %u\n", a+1, &a+1);
return 0;
}
Answer: B
Correct answer: 65480, 65496
a is a 3×4 array of 2-byte ints. a alone decays to a pointer to its first row, so adding 1 skips one row of 4 ints:
&a is a pointer to the whole array, so adding 1 skips all 12 ints:
Same address, different type - and the type is what decides how far +1 moves.
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