C
csx
Hi everyone!
two quick questions relating to arrays.
Q1,
Is it possible to re-assign array elements?
int array[2][2] = {{2,4}, {4,5}};
array[1][1] = {2,3}
just causes compiler errors! Do I have to assign at the beginning?
Q2,
My other 'main' question relates to 2-Dimensional arrays.
I need to create the size of my 2D array at run time. I have a couple of
functions that provide the dimensions I need. I need to call the function
like:
two_dimensional_array(maxRows, numLeafs)
but then, assign the values after, hence my first question. Can values be
asigned after?
Here is the code I currently have? Is this a good implementation? Any
suggestions would be much appreciated.
int ** myArray = 0; // in C++ 0==NULL
void two_dimensional_array(int rows, int cols)
{
int Rows, Cols;
if (myArray != NULL) {
for (int i = 0; i < Rows; i++) {
myArray = new int[Cols];
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
myArray = new *int[Rows];
return 0;
}
two quick questions relating to arrays.
Q1,
Is it possible to re-assign array elements?
int array[2][2] = {{2,4}, {4,5}};
array[1][1] = {2,3}
just causes compiler errors! Do I have to assign at the beginning?
Q2,
My other 'main' question relates to 2-Dimensional arrays.
I need to create the size of my 2D array at run time. I have a couple of
functions that provide the dimensions I need. I need to call the function
like:
two_dimensional_array(maxRows, numLeafs)
but then, assign the values after, hence my first question. Can values be
asigned after?
Here is the code I currently have? Is this a good implementation? Any
suggestions would be much appreciated.
int ** myArray = 0; // in C++ 0==NULL
void two_dimensional_array(int rows, int cols)
{
int Rows, Cols;
if (myArray != NULL) {
for (int i = 0; i < Rows; i++) {
myArray = new int[Cols];
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
myArray = new *int[Rows];
return 0;
}