I need to build a two dimensional array with three columns and a variable number of rows. The number of rows is to be determined by the user's input. I've tried defining an array as follows:
int My_Array[2][rows];
where "rows" is a value defined by the user during program execution (am I right in thinking that runtime is when the program is first run and execution is the period during which it is running?)
can anyone point me in the right direction on this?
That would be incorrect. You have to do it like this:
1 2 3 4 5
int *myArray[2]; //This is a one-dimensional array of two pointers to int.
//Now you obtain the number that is variable from the user.
//Then you instantiate the final arrays:
myArray[0] = newint[rows];
myArray[1] = newint[rows];
First of all I would like to note that the left subscript denotes rows and the right subscript denotes column. Moreover if you are speaking about three columns then the definition of the array shall include the number 3. So it could be as
int My_Array[rows][3];
However the C++ Standard requires that values of subscriptirs shall be constant expression. So the above declaration is invalid because rows is not a constant expression.
So you may allocate such arrayy in dynamical memory on the fly.