281 views

1 Answer

1 votes
1 votes
Note that: *(*(p + i) + j) and *(*(i + p) + j) is same.
Similarly *(*(j + p) + i) and *(*(p + j) + i) is equivalent.

printf can be rewritten as: printf ("%d %d %d %d", p[i][j], p[j][i], p[i][j], p[j][i])
since *(p + offset) is equivalent to p[offset].

This would print successive values of the array 'a' as i iterates from [0, 2) and

j iterates from [0, 3):
1 1 1 1
2 2 2 2
3 3 3 3
2 2 2 2
3 3 3 3
4 4 4 4

For eg on first iteration of i and j,
it would print 1, 1, 1, 1 since i == 0 and j == 0

When i == 0, and j == 1
p[i][j]
== p[0][1]
== 2
 
and p[j][i]
== p[1][0]
== 2
 
So it would print 2 2 2 2
and so on.

Related questions

0 votes
0 votes
1 answer
1
Debargha Mitra Roy asked Apr 16
76 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...