in Programming in C edited by
5,061 views
0 votes
0 votes
What would be the equivalent pointer expression for referring the array element a[i][j][k][l]?

A.    ((((a+i)+j)+k)+l)
B.    *(*(*(*(a+i)+j)+k)+l)
C.    (((a+i)+j)+k+l)
D.    ((a+i)+j+k+l)
in Programming in C edited by
5.1k views

1 comment

Let start form simple-

suppose we have a[i] then to access the element we use *(a+i)

if we have a[i][j] then to access the element we use *(*(a+i)+j)

using the same methodology we can say a[i][j][k]=*(*(*(a+i)+j)+k)

and finally a[i][j][k][l]=*(*(*(*(a+i)+j)+k)+l)

Correct me if i am wrong...
0
0

1 Answer

5 votes
5 votes
Best answer

*( *( *( *( a + i ) + j ) + k ) + l )

$*(a + i) \rightarrow a[i]$

$*(*(a + i) + j ) \rightarrow a[i][j]$

$*(*(*(a + i) + j )+k) \rightarrow a[i][j][k]$

$*(*(*(*(a + i) + j )+k) + l ) \rightarrow a[i][j][k][l]$

1. https://www.geeksforgeeks.org/pointers-in-c-and-c-set-1-introduction-arithmetic-and-array/

2. https://www.geeksforgeeks.org/multidimensional-pointer-arithmetic-in-cc/

selected by