0

How many row and columns does this array have?

int multiArr[1][3]

15th Apr 2017, 1:54 AM
Cody Rash
Cody Rash - avatar
3 odpowiedzi
+ 8
1 row. 3 columns
15th Apr 2017, 2:30 AM
Pixie
Pixie - avatar
+ 8
1 row and 3 columns. An example : 3 6 9 (3 elements in 1 row and 3 columns)
15th Apr 2017, 3:51 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
0
The most common interpretation would be that [1][3] means 1 row and 3 columns, and for most implementations, this will be the most direct. Consider printing: const unsigned rows = 1, cols = 3; int multiArr[rows][cols] = {1, 2, 3}; for (unsigned i = 0; i < rows; i++) { for (unsigned j = 0; j < cols; j++) std::cout << multiArr[i][j] << ' '; std::cout << std::endl; } The above prints out: 1 2 3 However, you aren't forced to interpret it this way; it could just as well mean 1 column and 3 rows. Consider the following modifications to the above: const unsigned cols = 1, rows = 3; int multiArr[cols][rows] = {1, 2, 3}; for (unsigned j = 0; j < rows; j++) { for (unsigned i = 0; i < cols; i++) std::cout << multiArr[i][j] << ' '; std::cout << std::endl; }. The above prints out: 1 2 3
15th Apr 2017, 5:35 AM
Zack Strickland
Zack Strickland - avatar