wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Which one of the choices given below would be printed when the following program is executed?

#include <stdio.h>
int a1 [ ] = {6, 7, 8, 18, 34, 67};
int a2 [ ] = {23, 56, 28, 29};
int a3 [ ] = {-12, 27, -31};
int *x [ ] = {a1, a2, a3};
void print ( int &a[ ] )
{
printf("%d", a[0][2]);
printf("%d", *a[2]);
printf("%d", *++a[0]);
printf("%d", *(++a)[0]);
printf("%d\n", a[-1][+1]);
}
main( )
{
print(x);
}

A
-12, -12, 27, -37, 56
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
8, -12, 7, 23, 8
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
-12, -12, 27, -31, 23
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
8, 8, 7, 23, 7
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B 8, -12, 7, 23, 8

*a[ ] = &x;
*a[ ] contain base address of array x;

1. Printf (a[0] (2}) =*(*(a +0) +2)
= *(100 +2×4)
= *(108)
= 8

2. Printf (*a[2]) = *(*(a + 2) + 0)
= *(408 + 0)
= *(408)
= -12
3. Printf (*++ a[0]) = *(++(a + 0))
= *(++(100))
= *(104)
= 7

4. Printf (*(++ a)[0]) = *(*(a + 1) + 0)
= *(*(404) + 0)
= *(200 + 0)
= *(200)
= 23

5. Printf (a[-1] [+1]) = *(*(a — 1) + 1)
= *(*(404-4) +1)
= *(104+1)
= *(104 + 1 × 4)
= *(108)
= 8

Note: In step 3 ‘a1’ point to ‘a1’ = 104 and in step 4 ‘a’ point to 404 as starting address used

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Playing with 2 - Digit and 3 - Digit Numbers
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon