This is one of the reasons pointers must be well understood by the 'C' programmer. In C, multi-dimensional arrays consist of pointers to pointers to pointers (ad infinitum) to data. This can be seen thus:
A two dimensional array of characters.. int myarray[10][10]; the first dimension is an array of 10 pointers, each pointing to the beginning of an array of 10 integers. Int myarray[10][10][10]; This is an array of 10 pointers,each pointing to an array of 10 pointers, each pointing to the beginning of an array of 10 integers. Remembering in 'C' there is no guarantee that the all dimensions will be located in contiguous memory, Only the individual arrays. This is because of the way the compiler translates the array accesses. int myarray[10]; int x; x = myarray[5]; this is translated by the compiler into x=*(myarray + 5); It's important to understand this concept. It's what allows is tricky and cool c programmers to write things like char mystring = "this is a test of the system"; while (*mystring) putc (*mystring++); I hope this is somewhat clear.. It is to me but I've been writing in c for a long time.. Michael _____ From: [email protected] [mailto:[email protected]] On Behalf Of Ahmed Mahmoud Sent: Monday, May 11, 2009 10:26 AM To: [email protected] Subject: Re: [c-prog] Difference b/w pointer to pointer and 2D arrays Hi,The difference between pointer to pointer and 2D Array is that: First 2D Array:The 2d Array is used -often-for tables for ex:int A[3][2] this means that this has 3 rows and 2 coloum you can imagine that second pointer to pointer:we know that the pointer is used to hold the address the pointer to pointer is used to hold the address of another pointer ex:int**x; Thanks Eng A.Mahmoud eng_hamada2585@ <mailto:eng_hamada2585%40yahoo.com> yahoo.com eng.hamada2585@ <mailto:eng.hamada2585%40gmail.com> gmail.com OR send your asks to ah_...@yahoogroups. <mailto:ah_man%40yahoogroups.com> com http://sites. <http://sites.google.com/site/eng7amadaprogramming/> google.com/site/eng7amadaprogramming/ http://tech. <http://tech.groups.yahoo.com/group/eng_7amada_for_programming_works/> groups.yahoo.com/group/eng_7amada_for_programming_works/ --- On Mon, 5/11/09, Thomas Hruska <thru...@cubiclesoft <mailto:thruska%40cubiclesoft.com> .com> wrote: From: Thomas Hruska <thru...@cubiclesoft <mailto:thruska%40cubiclesoft.com> .com> Subject: Re: [c-prog] Difference b/w pointer to pointer and 2D arrays To: c-p...@yahoogroups. <mailto:c-prog%40yahoogroups.com> com Date: Monday, May 11, 2009, 6:23 AM amir.khalid@ ymail.com wrote: > Any one please tell me what is the diff b/w pointer to pointer and 2D array. A "2D array", from your perspective, is perhaps best viewed as a subset of a "pointer to pointer". In a 2D array, all the rows/cols have the same length: ***** ***** ***** ***** ***** With a "pointer to pointer", you can do: ******* ** **** ****** * -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleS oft.com/MyTaskFo cus/ [Non-text portions of this message have been removed] [Non-text portions of this message have been removed]
