Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
What will this program output?
“`C++
#include
class Matrix {
public:
Matrix(int rows, int cols) : rows(rows), cols(cols) {
data = new int*[rows];
for (int i = 0; i < rows; ++i) {
data[i] = new int[cols];
for (int j = 0; j < cols; ++j) {
data[i][j] = i * cols + j + 1;
}
}
}
~Matrix() {
for (int i = 0; i < rows; ++i) {
delete[] data[i];
}
delete[] data;
}
void print() const {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
std::cout << data[i][j] << " ";
}
std::cout << std::endl;
}
}
private:
int** data;
int rows;
int cols;
};
int main() {
Matrix matrix(3, 4);
matrix.print();
return 0;
}
```
It consoles 4 x 3 matrix , 1 2 3 4 in row one , 5 6 7 8 in row two and 9 10 11 12 in row 3
CONTRIBUTE TO THIS THREAD