Solved

Need an In-depth pointer explanation

Posted on 2002-07-26
4
195 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

635 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