Require Help with the Cinema Seat Assignment (Multi-Dimensional Arrays) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Require Help with the Cinema Seat Assignment (Multi-Dimensional Arrays)

I attempted running my code several times but the output kept returning this "0x7ffc66983350" and I have no clue what's wrong. #include <iostream> using namespace std; int main() { int rows = 6; int cols = 6; float matrix[rows][cols] = { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, }; // your code goes here for (int rows = 0; rows < 6; rows++){ for (int cols = 0; cols < 6; cols++){ matrix[rows][cols] = 1; } } cout << matrix; return 0; }

23rd May 2021, 10:01 PM
Xiveski
Xiveski - avatar
2 Answers
+ 1
What you are seeing is the memory address of the first element in the array, as plain arrays decay to pointers in many contexts. std::cout is not overloaded to print array types. You need to print each element manually if you wish to do so. In this case, another nested loop could do the job, by iterating over the rows and columns and printing all elements of a row, while inserting a new line after each printed row.
23rd May 2021, 10:10 PM
Shadow
Shadow - avatar
0
Just fixed my code and it works. Thank you! @Shadow
23rd May 2021, 10:25 PM
Xiveski
Xiveski - avatar