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?
Quick question about pointers
if I declare a pointer like this:
"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];
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
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]
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]
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 ?
Maybe if you explained what you are trying to implement ?
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?
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?
an array of pointers to arrays:
int** pTemp;pTemp = new int*[50];for(int i = 0; i < 50; i++){ pTemp[i] = new int[50];}
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]
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
Popular Topics
Advertisement