2D Array and Double Pointer in C | Toolbox Tech - Spiceworks
文章推薦指數: 80 %
In expressions the name of an array is converted to a pointer to its first element. As arr is a two-dimensional array when arr is converted to int ( * )[4].
EXPLORE
FOLLOWUS
Facebook
Twitter
LinkedIn
RSS
Youtube
Home
News&Insights
News&InsightsHome
Innovation
ITCareers&Skills
Cloud
CyberSecurity
FutureofWork
AllCategories
Marketing
HR
Finance
Community
Askquestion
CommunityHome
SpiceworksOriginals
Cloud
Collaboration
Networking
WaterCooler
Windows
Allforums
How-Tos
Scripts
Vendors
Meetups
Reviews
OnlineEvents
Login
Join
Login
Join
Toolbox.comhasbecomeSpiceworksNews&Insights.Here'swhy.
Programming
2DArrayandDoublePointerinC
8.77KviewsJuly25,2020
AnirbanRoy
November18,2011
0Comments
“#include
intmain()
{
intarr[][4]={
{12,23,34,45},
{56,67,78,89}
};
int**ptr=NULL;
ptr=(int**)arr;
printf(“nThearrayfirstelementAccess%d%d”,arr[0][0],*ptr);
ptr++;
printf(“nThearrayfirstelementAccess%d%d”,arr[0][0],*ptr);
printf(“nThearrayfirstelementAccess%d%d”,arr[0][0],*(*(ptr+0)+0));
printf(“nThearrayfirstelementAccess%d%d”,arr[0][0],**ptr);
return0;
}
//itisshowingfor**ptr
CananyonepleaseexplainmewhyIcannotaccess2Darrayusingdoublepointer
//forthislineptr=(int**)arrcompilerdoesnotcomplainbutforaccessingitisshowing
//problemfordoubleindirection.”
8
Answers
AnuroopJesu
PostedNovember18,2011
0
Comments
Hianirban_roy,
BeforeIgiveanyexplanationletmegivesomeinformationonthehowtheelementsarestoredinthearray2D
intarr[][4]={{12,23,34,45},{56,67,78,89}};
–Alltheelementsintheabovearrayarestoredinthesequentialmemoryaddressandthisisequivalenttointarr[]={12,23,34,45,56,67,78,89};
SoMultidimensionalarraysarerepresentedasthesingledimensionandcompleteabstractionisprovidedbycompilertoprogrammer
Nowcomingbacktothedoublepointer,thedoublepointercanonlystoretheaddressofthepointersoifyoustillwanttoaccessthe2Darrayusingdoublepointerthenthiscanbedoneasgivebelow
#include
延伸文章資訊
- 1How to pass to 2-dimensional int array to a function ... - Quora
(I suggest avoiding the term “double pointer” unless you're talking about the type [code ] ... Th...
- 2Lecture 06 2D Arrays & pointer to a pointer(**)
Accessing a 2D array using pointers. •. ** or pointer to a pointer. •. Passing pointer to a funct...
- 32D Array and Double Pointer in C | Toolbox Tech - Spiceworks
In expressions the name of an array is converted to a pointer to its first element. As arr is a t...
- 4Arrays and pointers in C - Ibiblio
QED Why a double pointer can't be used as a 2D array? ... The 2D array is "equivalent" to a "poin...
- 52D Arrays and Double Pointers - Bryn Mawr College