You are getting confused with the pointers. p[0]
is a pointer to int
, so is p[1]
.
The code makes p[0]
and p[1]
point to the same address:
p[1] = p[0];
This has the effect that p[i][j]
refers to the same object whether i
is 0 or 1. The nested loops will access p[0][0]
in the first place, setting it to 0, but then later p[1][0]
(which is the same object as p[0][0]
is accessed, which causes it to be assigned 1.
The key point here is that p[0][0]
and p[1][0]
are the same.