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]
Discussion:
70 comments Page 2 of 7.
Sameer said:
1 decade ago
Pointer1.c: In function main:
Pointer1.c:5: Error: ptr undeclared (first use in this function).
Pointer1.c:5: Error: (Each undeclared identifier is reported only once.
Pointer1.c:5: Error: for each function it appears in).
Pointer1.c:5: Error: ptr undeclared (first use in this function).
Pointer1.c:5: Error: (Each undeclared identifier is reported only once.
Pointer1.c:5: Error: for each function it appears in).
Ramana said:
1 decade ago
Can any one tell what will be the output of this program:
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)) ;
}
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)) ;
}
Rawat said:
1 decade ago
I know very well that *(a+i) = a[i];
Then *(*(*(*(a+i)+j)+k)+l) = *(*(*(a[i]+j)+k)+l).
Let a[i] = x;
Then*(a[i]+j) = *(x+j) = x[j]
So x[j] = a[i][j];
Continue in same manner,
*(*(a[i][j]+k)+l).
*(a[i][j][k]+l).
a[i][j][k].
Then *(*(*(*(a+i)+j)+k)+l) = *(*(*(a[i]+j)+k)+l).
Let a[i] = x;
Then*(a[i]+j) = *(x+j) = x[j]
So x[j] = a[i][j];
Continue in same manner,
*(*(a[i][j]+k)+l).
*(a[i][j][k]+l).
a[i][j][k].
Gopi reddy said:
1 decade ago
If we want to refer one dimensional we just use single pointer ie like *p, if we need to refer two dimensional we have to use double pointer reference ie *(*p), if we have to refer 4 at a time just use 4 pointer statement i.e. *(*(*(*(p))))and so on.
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] = *(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)
Mamta said:
1 decade ago
One dimensional array represent by*p.
And two dimension with (*(*p)).
Three dimensional with (*(*(*p)))) and so on....
And two dimension with (*(*p)).
Three dimensional with (*(*(*p)))) and so on....
Souvik maitra said:
1 decade ago
Why is it a+i? What does + denotes?
Atul Mithe said:
1 decade ago
If we want to refer one dimensional we just use single pointer ie like *p, if we need to refer two dimensional we have to use double pointer reference ie *(*p), if we have to refer 4 at a time just use 4 pointer statement i.e. *(*(*(*(p))))and so on..
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] = *(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)
Luso said:
1 decade ago
Hi @All.
In short no of brackets used must be equal to no of pointer operator used it's case of representation of array.
Actual representation of multidimensional array in memory is linear.
In short no of brackets used must be equal to no of pointer operator used it's case of representation of array.
Actual representation of multidimensional array in memory is linear.
Sweta jain said:
8 years ago
Thanks @Ramanaji.
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).
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).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers