Public Group

#### Archived

This topic is now archived and is closed to further replies.

This topic is 5280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
"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];

##### Share on other sites
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]

##### Share on other sites
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 ?

##### Share on other sites
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?

##### Share on other sites
an array of pointers to arrays:

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

##### Share on other sites
That is exactly what I wanted! Thanks ^_^

##### Share on other sites
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]

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011320
• ### Who's Online (See full list)

There are no registered users currently online

×