With int (*p)[5] and 4-byte ints, by how many bytes does p + 1 advance?
Correct answer
C. 20
17 views
C. 20
17 views
Pointer arithmetic scales by the size of the pointed-to type, and here that type is int[5], which occupies 20 bytes. This is why a pointer to an array steps one whole row at a time in two-dimensional arrays. By contrast int *q[5] declares an array of five pointers, and q + 1 there would move by one pointer only.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.