2 dim numbers..
-
Are you simply wanting a 2D array?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Are you simply wanting a 2D array?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Thanks atlast got a reply. No I'm not simply wanting a 2D Array. An array is a group of memory locations that we reserve, Ok in the below statement, I've reserved. 6 Memory locations that has the capability to store 6 integers. And I've got a pointer pointing to that. int* pInt = new int[2*3]; The dimension. It's how we look at the reserved memory location. The memory as of now, looks like : [] [] [] [] [] [] ^ Incrementing the pInt's value would make it go like : [] [] [] [] [] [] -+^ [] [] [] [] [] [] ---++^ This is linear. We can do the same with pInt[0],[1]..etc. Ok this about looking at the memory locations in 1D. Now I want to look at it in 2D. The same memory location. I would want to initialize a 2D pointer to the same memory location. Where I should be able to mention 2 indices. You may take it as 2x3 or 3x2 when you say 2x3, That says, 2 rows and 3 elements in each row. [] [] [] [] [] [] Now tell me how should declare a pointer to the memory location that it would access them as 2D. int* pInt = new int[2*3]; int(** ptr2D)[2][3] = new int*[2]; <--something like this. NOT SURE. If we are gonna look at the same memory locations as 3x2, then it becomes. [] [] [] [] [] [] Here ptr2D[2][0].. would make sense. Because, The number of rows, 0th row, 1th row, 2nd row. Has 3 rows. But in the former case, it would crash because we were looking at it as 2 rows with 3 columns. My question makes sense?
---------------------------- 286? WOWW!:-O
-
It does not matter. pInt[2][3] is the same as pInt[3][2].
Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]
-
It does not matter. pInt[2][3] is the same as pInt[3][2].
Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]
Rage wrote:
It does not matter. pInt[2][3] is the same as pInt[3][2].
Oh, you've said like this? Ok, take up the first one., pInt[2][3]; Try Printing the element pInt[3][0]."Boom" !??!. How can this be eqivalent to pIntp[3][2]. The dimension is different and that's what the question is all about. Looking the same block of memory with different dimensions.
---------------------------- 286? WOWW!:-O
-
I don't think you can do what you're trying to do. If you can, I'd like to see the syntax. For a 2 dimension array like this: int myarray[2][3]; myarray is not a pointer. You can't cast an int pointer to the type of myarray (AFAIK). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Thanks atlast got a reply. No I'm not simply wanting a 2D Array. An array is a group of memory locations that we reserve, Ok in the below statement, I've reserved. 6 Memory locations that has the capability to store 6 integers. And I've got a pointer pointing to that. int* pInt = new int[2*3]; The dimension. It's how we look at the reserved memory location. The memory as of now, looks like : [] [] [] [] [] [] ^ Incrementing the pInt's value would make it go like : [] [] [] [] [] [] -+^ [] [] [] [] [] [] ---++^ This is linear. We can do the same with pInt[0],[1]..etc. Ok this about looking at the memory locations in 1D. Now I want to look at it in 2D. The same memory location. I would want to initialize a 2D pointer to the same memory location. Where I should be able to mention 2 indices. You may take it as 2x3 or 3x2 when you say 2x3, That says, 2 rows and 3 elements in each row. [] [] [] [] [] [] Now tell me how should declare a pointer to the memory location that it would access them as 2D. int* pInt = new int[2*3]; int(** ptr2D)[2][3] = new int*[2]; <--something like this. NOT SURE. If we are gonna look at the same memory locations as 3x2, then it becomes. [] [] [] [] [] [] Here ptr2D[2][0].. would make sense. Because, The number of rows, 0th row, 1th row, 2nd row. Has 3 rows. But in the former case, it would crash because we were looking at it as 2 rows with 3 columns. My question makes sense?
---------------------------- 286? WOWW!:-O
_8086 wrote:
Now tell me how should declare a pointer to the memory location that it would access them as 2D.
int **p = new int*[FirstDimension];
for(int i = 0; i < FirstDimension; i++)
{
p[i] = new int[SecondDimension];
for(int j = 0; j < SecondDimension; j++)
{
p[i][j] = 0;
}
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
_8086 wrote:
Now tell me how should declare a pointer to the memory location that it would access them as 2D.
int **p = new int*[FirstDimension];
for(int i = 0; i < FirstDimension; i++)
{
p[i] = new int[SecondDimension];
for(int j = 0; j < SecondDimension; j++)
{
p[i][j] = 0;
}
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Rage wrote:
It does not matter. pInt[2][3] is the same as pInt[3][2].
Oh, you've said like this? Ok, take up the first one., pInt[2][3]; Try Printing the element pInt[3][0]."Boom" !??!. How can this be eqivalent to pIntp[3][2]. The dimension is different and that's what the question is all about. Looking the same block of memory with different dimensions.
---------------------------- 286? WOWW!:-O