March 13, 2024
March 13, 2024
Question 5152 – Finite-Automata
March 13, 2024
March 13, 2024

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

```#include
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);
}```

Question 22 Explanation:
1) a[0][2] = *(*(a+0)+2)
It returns the value of 3rd element in a1.
First printf print 8.
2) *a[2] = *(*(a+2))
It returns the value of 1st element in a3.
Second printf print -12.
3) *++a[0] = *(++(*(a+0)))
a[0] is pointing to 1st element in a1.
++a[0] – after preincrement performed, now a[0] is pointing to 2nd element in a1.
*++a[0] return the value of 2nd element in a1.
Third printf print 7.
4) *(++a)[0]
++a – after preincrement is performed ‘a’ is pointing to a2.
(++a)[0] is pointing to 1st element in a2.
*(++a)[0] returns the value of 1st element in a2.
Fourth printf print 23.
5) a[-1][+1] = *(*(a-1)+1)
(a-1) is pointing to a1.
*(a-1) is pointing to the 2nd element in a1, because in 3rd printf already a1 was incremented by 1.
*(a-1)+1 is pointing 3rd element in a1.
*(*(a-1)+1) returns the value of 3rd element in a1, i.e., 8.
8, -12, 7, 23, 8
8, 8, 7, 23, 7
-12, -12, 27, -31, 23
-12, -12, 27, -31, 56