C Programming - Pointers - Discussion

Discussion Forum : Pointers - General Questions (Q.No. 6)
6.
What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
((((a+i)+j)+k)+l)
*(*(*(*(a+i)+j)+k)+l)
(((a+i)+j)+k+l)
((a+i)+j+k+l)
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
70 comments Page 4 of 7.

Ankit Jain said:   1 decade ago
a[i] = *(a+i).

a[i][j] = *(a[i]+j) = *(*(a+i)+j).

a[i][j][k]= *(a[i][j]+k)= *(*(a[i]+j)+k) = *(*(*(a+i)+j)+k).

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

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

Rajasimhan said:   1 decade ago
Let A[3][3] be a matrix.


A(address =50) --------> (address 60) ------>(address 100).
(address 61) ------>(address 103).
(address 62) ------>(address 106).

Now to get A[2][2] = *(*(*(50)+2)+2)
= *(*(60+2)+2)
= *(*(62)+2)
= *(106+2)
= *(108).

= value at address 108.

Aseil said:   1 decade ago
@Mark. I TRIED TO CLEAR IT BY THIS PROGRAM:

#include<stdio.h>

int main()

{
int a[2][2]={1,2,3,4};
printf("val address\n");
printf("%d %d\n",*(*(a)),*(a));
printf("%d %d\n",*(*(a)+1),*(a)+1);
printf("%d %d\n",*(*(a+1)),*(a+1));
printf("%d %d\n",*(*(a+1)+1),*(a+1)+1);

return 0;
}

Try to make some diagram to understand this and I am sure if you do so it will be clear.

Mark said:   1 decade ago
Please, someone clear my doubt.

main()
{
int a[2][2]={1,2,3,4};
printf("%d %d",a+1,*(a+1));
}

In this problem both values of printf are same.. how could it.. if a+1 denotes address of a[1][0], then *(a+1) should display its value, but why not..??? please explain ?

Kuldeep said:   1 decade ago
As a[i] == *(a+i)
a[i][j]== *(*(a+i)+j))

Maxx said:   1 decade ago
Subscript is mainly variable which show an index of a particular member of d array, it is mainly use to access some member of array. Like a[i]...... Here I is a subscript variable. Which will access I the member of the array.

Cherry said:   1 decade ago
@Rishitha
In c language , subscript is used to allocate memory location using index in array

Rishitha said:   1 decade ago
What is subscript?

Mrutyunjay said:   1 decade ago
We can write a[i] in pointer as *(a + i)
similarly a[i][j] as *(*(a+i)+j)
a[i][j][k] as *(*(*(a+i)+j)+k)
a[i][j][k][l] as *(*(*(*(a+i)+j)+k)+l)

Khushi said:   1 decade ago
Thanks raju naidu.

Nice explanation :).


Post your comments here:

Your comments will be displayed after verification.