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.
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)) ;
}
Ramanaji 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.....
(2)
Ashok said:
1 decade ago
Given: a[i][j][k][l]
i number of rows with
{
each contains j number of rows with
{
each contains k number of rows with
{
EACH CONTAINS l no of columns
}
}
}
i number of rows with
{
each contains j number of rows with
{
each contains k number of rows with
{
EACH CONTAINS l no of columns
}
}
}
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.
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].
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).
Suma sahithi said:
1 decade ago
Array itself is a pointer. If we creat an array it defaultly takes address of 1st element, so to take value in that address we should place * before it. As it is a 4 dimentional array we should place * before each one.
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).
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.
Praveen said:
1 decade ago
Hi @Suma sahiti, array is not a pointer, array is an sequential collection of elements of similar data types, but pointer is a variable which holds the address of another variable.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers