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 1 of 7.

Radhika said:   8 months ago
Thank you for explaining the answer.

Chitti said:   2 years ago
Here is the coding part;


#include<stdio.h>
int main ()
{
int arr[2][3]={5, 10, 15, 20, 25, 30};
int (*ptr) [2][3]=&arr;
printf ("%d\t", ***ptr);
printf ("%d\t", ***(ptr+1));
printf ("%d\t", **(*ptr+1));
printf ("%d\t", *(*(*ptr+1)+2));
return 0;
}
(2)

Sneha said:   2 years ago
Here is the coding part;


#include<stdio.h>
int main ()
{
int arr[2][3]={5, 10, 15, 20, 25, 30};
int (*ptr) [2][3]=&arr;
printf ("%d\t", ***ptr) ;
printf ("%d\t", ***(ptr+1)) ;
printf ("%d\t", **(*ptr+1)) ;
printf ("%d\t", *(*(*ptr+1)+2)) ;
return 0;
}
(4)

Adi said:   3 years ago
Thanks @Pradeep and @Ramanaji.

Sairam said:   6 years ago
Thank you @Pradeep.

Suraj said:   6 years ago
Thanks @Ramanaji.
(1)

Ajay said:   6 years ago
Thanks, @Pradeep.
(1)

Er. Rohit Deshmukh said:   6 years ago
Here In the above problem "a" is an Array having $ dimensions.

Which indicates that a is a pointer and i , j , k , l are offset values.

Let Us Consider An Example : Of An Array;

int ptr = a + i;
where a is Base address and i is Offset,
now it gives address of a[i] which is in integer form
Hence we will it into address as *(a+i) ;
and then add it with the 2-nd offset i.e. j -> *(a+i)+j.

Similarly The Process Continues as Follows:
Address = *(a+i)+j Offset = k
new Address = (*(*(a+i)+j)+k)
Address = *(*(a+i)+j)+k Offset = l
new Address = *(*(*(a+i)+j)+k)+l

And Then Finally The Address Of The Element a[i][j][k][l] = *(*(*(*(a+i)+j)+k)+l).
(2)

Immanuvel said:   6 years ago
Such a wonderful explanation and I can easily understand that. Thank you @Ramanaji & @Pradeep.

Sumi said:   6 years ago
a[i] =*(a+i) .

I can't understand this, please explain.


Post your comments here:

Your comments will be displayed after verification.