Quick question about pointers

Started by
6 comments, last by uber_n00b 19 years, 10 months ago
if I declare a pointer like this:

int *i[3]
Am I making an array of pointers or a pointer to an array? If not, how do I make an array of pointers?
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Advertisement
"int *i[3]" declares an array of pointers.
I too sometimes get confused with this kind of stuff,and i''ve seen that typedef makes my programs more readable.

Example:
typedef int *Pint;
Pint i[3];

OK well I have another problem then. How do I make an array of pointers that in turn points to an array?

I tried to do

bool *booleans = new boolean[5][3];


But yeah didn't work. How should I do it? I mean am I making myself clear enough? Should I make a vector of boolean*?

[edited by - uber_n00b on June 1, 2004 3:40:40 PM]
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
The array name points to the first element of the array, with a little abuse, we could say that arrays are pointers.

Maybe if you explained what you are trying to implement ?
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
Alright here''s the setup: I have an octree and each node contains three different sets of details: low detail, medium detail and high detail. Each level of detail stores the polygons in this way:

POLYGON *POLYS = new POLYGON[NUM_POLYS].

How do I create an array such that low, medium and high detail can be stored in one array that each element holds the pointer to the array which holds the polygons? Does that make sense?
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
an array of pointers to arrays:

int** pTemp;pTemp = new int*[50];for(int i = 0; i < 50; i++){  pTemp[i] = new int[50];}

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

That is exactly what I wanted! Thanks ^_^
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
I'm not 100% this is the only way to do this,but here goes:

say for a 10x5 array:

bool (*booleans)[10]=new bool[5][10];
so you see that the number of columns must be known in compile-time

If you want to be able to define both rows and columns in run-time,do this:

bool **i;
i=new bool*[ROWS];//Create an array of arrays
for (int j=0;j{
i[j]=new bool[COLUMNS];//Create an array of bools
}


-EDIT:Oops,I see Etnu was faster than me.Oh well,we boid said the exact same thing.



[edited by - mikeman on June 1, 2004 4:14:23 PM]

This topic is closed to new replies.

Advertisement