0

How to initialise double pointer to 2d array..

In C

24th Apr 2022, 1:32 PM
Prabhas Koya
5 Réponses
+ 1
int arr[2][2] = {{1,2},{3,4}}; int (*Ptr)[2] = arr; printf("%d",(*(Ptr+1))[1]); // Displays 4
24th Apr 2022, 5:53 PM
John Wells
John Wells - avatar
+ 1
As addition you would probably need such things for passing an array to a function but in C you have to pass dimensions too because pointers doesn't carry any info about length. Now if you have a function tacking a rectangular matrix you would pass it as plain array and use X and Y dimensions to get values out of it
25th Apr 2022, 9:45 AM
AZTECCO
AZTECCO - avatar
0
int arr[2][2] = {1,2,3,4}; int **Ptr = arr ; this is not working
24th Apr 2022, 1:33 PM
Prabhas Koya
0
John Wells i am asking about double pointer
25th Apr 2022, 5:21 AM
Prabhas Koya
0
int arr[2][2] = {1,2,3,4}; int* Ptr[] = {arr[0],arr[1]} ; main(){printf("%d %d %d",Ptr[0][0],Ptr[0][1],Ptr[1][0]);} You simply can't the way you did. A double pointer doesn't exist, you probably meant a pointer to pointer which is a pointer to array of pointers to arrays of Type
25th Apr 2022, 9:34 AM
AZTECCO
AZTECCO - avatar