Go Premium for a chance to win a PS4. Enter to Win

x
Solved

Need an In-depth pointer explanation

Posted on 2002-07-26
Medium Priority
197 Views
I have an array declared like this...

Float64 (* rawData[2]) [2];

It gets accessed like this...

Float64 packedData = rawData[0][0][0];

How is this accessed as a three dimensional array?  I am confused because, as I see it, rawData is an array of pointers to arrays of Float64's.  I just can't seem to get my head around this.  Why can't it be accessed like this...

Float64 packedData = rawData[0][0];

Can somebody give me a detailed explanation?  Perhaps a few visual aids?  I can't seem to visulize this as a 3D array.

Thanks a lot
0
Question by:kirts
• 2

LVL 32

Accepted Solution

jhance earned 400 total points
ID: 7180346
There is a rough equivalency between a pointer to an object and an array of objects.  So if you have something like:

int *p;

you can access the CONTENTS of p with:

int q = *p;  // q gets the CONTENTS of what p points to

but also with:

int q = p[0];

In this case, p[0] is equivalent to *p.  So just extend this to greater indirection:

int **p;
int q = **p;
int q = p[0][0];

In your example declaration, you are mixing the * and [] syntax which is OK...

So you have the equivalent of:

int (* p[2])[2];

which is declaring an array of 2 int pointers 2 times.  (The parentheses are redundant here.)

So an item in this (confusing mess) can be accessed like:

q = p[0][0][0];

or

q = *p[0][0];
0

Expert Comment

ID: 7180775
the thing is an array of pointers to an array
that is
Its an Array of Pointers
the rawData[2] which are pointing to a array of Float64

so u have array of pointers (that is a 2 d array) each of these pointers is pointing to an array of Float64 so there u have the 3 dimension

i cant make a diagram here but hope the above paragraph helps
0

Author Comment

ID: 7180904
Wicked.  Thanks alot for the explanation.  Pointer notation can get so crazy.
0

LVL 32

Expert Comment

ID: 7181053
If you want to get a wizard at this, get this book:

http://www.softpro.com/0-201-60461-2.html

If you remember 10% of what's in it, you'll never miss a beat on this stuff again...
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month12 days, 16 hours left to enroll