Solved

Need an In-depth pointer explanation

Posted on 2002-07-26
4
194 Views
Last Modified: 2010-04-01
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
Comment
Question by:kirts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 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

by:Sabnis
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

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

Expert Comment

by:jhance
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question