Can you declare whole rows of a multi-dimensional array at one time? or do you have to go through and individually declare each spot one at a time?
Printable View
Can you declare whole rows of a multi-dimensional array at one time? or do you have to go through and individually declare each spot one at a time?
Code:int x[][5] = { { 1, 2, 3, 4, 5 },
{ 2, 4, 6, 8, 10 } };
I cant seem to get it to work. What are the second group of numbers for?
Try this:
Code:#include <iostream>
using namespace std;
int main(void)
{
int x[2][5] = {
{ 1, 2, 3, 4, 5 },
{ 2, 4, 6, 8, 10 }
};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 5; j++)
cout <<"x["<<i<<"]["<<j<<"] = " <<x[i][j] <<endl;
return(0);
}
/*
Output:
x[0][0] = 1
x[0][1] = 2
x[0][2] = 3
x[0][3] = 4
x[0][4] = 5
x[1][0] = 2
x[1][1] = 4
x[1][2] = 6
x[1][3] = 8
x[1][4] = 10
*/