![]() |
| |||||||
| Register | Resources | FAQ/Rules | Members List | Search | Today's Posts | Mark Forums Read | |
| Programming Anything related to programming... PHP, PERL, ASP, ColdFusion, C++, etc. |
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| TechSpott Newbie Join Date: Feb 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
![]() | Ok, two short questions. This is not homework, if you are wondering. The first question: consider this line: int multi[30][80]; Which of the following is 'multi' - An array of 30 arrays, each containing 80 ints - An array of 80 arrays, each containing 30 ints Second part of the question: If I did these three lines: int a = multi[5][15]; int** ptr = &multi[0][0]; int b = ptr[5][15]; is (a == b) for all cases? |
| | |
| | #2 (permalink) | |
| Junior Member Join Date: Feb 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
![]() | Quote:
Pointers-to-pointer (**) are usually used in two situations: 1. A pointer argument to a function that's expected to return a new value OF THE POINTER or 2. A pointer to an array of pointers. This is neither. In fact, int* ptr = &multi[0][0]; is the correct syntax. (Which is identical to int* ptr = multi; by the way.) So if the compiler permits subscript notation with a pointer (I don't remember if that's syntactically legal), yes, a would always have the same value as b. Hope that helps. | |
| | |
![]() |
| Bookmarks |
| Tags |
| arrays, multidimensional |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |