0

Answer of below code is 5. How _**(x+i+j)_ indicates x[3][0] memory location contain. Explain.

#include <stdio.h> int main (){ int x [4][5],i,j,k; for (i=0; i<4 ; ++i) for (j=0,k=1; j<5 ; j++){ x[i][j] = k; k++; } i=1; j=2; x[3][0] = 5; printf("%d",**(x+i+j)); return 0; }

28th Aug 2020, 2:47 PM
Nadim Zed
Nadim Zed - avatar
1 Odpowiedź
+ 3
the code creates a two dimensional array 4 x 5: 12345 first row 12345 2nd row 12345 3rd row 12345 4th row think of it like a table. x[3][0] means 4th row first column. (array index starts from 0.) x[3][0] = 5; now the array look like : 12345 first row 12345 2nd row 12345 3rd row 52345 4th row (notice 5) array name can be used as a pointer to the first element when it's dereferenced. incrementing x inside **( ) will go through rows. ie: **(x + 1) will point to the first value in 2nd row. so **(x + 1 + 2) will point to the first element in 4th row. because it's changed by x[3][0] = 5 it equals 5. if it were **(x) + i + j; i and j outside of **() it would mean 1 + 1 + 2
28th Aug 2020, 4:44 PM
Bahhaⵣ
Bahhaⵣ - avatar