I just started learning pointers ( 1 day ) and I can’t figure out how to pass a pointer from the create_matrix () function to main () , and in it already call another function (print_matrix) with a parameter as a pointer (array) from create_matrix () .
If not difficult, please make comments on the code.
#include <iostream> #include <cmath> #include <iomanip> using namespace std; void print_matrix(int** matrix, int size_l, int size_s) { for (int x = 0; x < size_l; x++) { for (int y = 0; y < size_s; y++) { cout << matrix[x][y] << setw(3); } cout << "\n"; } } int create_matrix(int size_m, int size_l, int size_s) { int** matrix = new int* [size_m]; for (int i = 0; i < size_m; i++) { matrix[i] = new int[size_m]; } cout << "Enter elements of matrix : " << endl; for (int x = 0; x < size_l; x++) { for (int y = 0; y < size_s; y++) { cout << "[" << x << "," << y << "]" << " << "; cin >> matrix[x][y]; } } return **matrix; } int main() { unsigned int array_size; unsigned int number_of_lines; unsigned int number_of_strings; cout << "Enter number of lines : "; cin >> number_of_lines; cout << "Enter number of strings : "; cin >> number_of_strings; array_size = number_of_lines * number_of_strings; create_matrix(array_size, number_of_lines, number_of_strings); //print_matrix(matrix, number_of_lines, number_of_strings); return 0; }
int**, then write -int** create_matrix(..., notint create_matrix(...Well, inmainperform the appropriate assignment to a variable of the same type. Which then pass toprint...- Harry