c++ Function creates a 2-d array and returns a pointer to the 2-D array -


i new c++ , learning use pointers , arrays. having hard time piece of code compiling , appears doing should, except output of pointer in main function appears memory address, must missing in way calling or returning pointer. (i hope got terminology right)

in main function, created pointer variable , initialized null (professor recommended initializing vars)

int** ptr1=null; 

next set pointer equal function, creates array

ptr1 = makearray1(); 

here code function.

int** makearray1() 

{

const int row = 2; const int col = 3;  int** array1 = new int* [row];                          //this creates first row of cols (int = 0; < row; i++)     {         array1[i] = new int[col];               //loop create next col of rows     }  (int = 0; < row; i++)     {         (int j = 0; j < col; j++)             {                 cout << endl << "please enter integer in first matrix: ";                 cin >> array1[i][j];             }     }  cout << endl;  (int = 0; < row;i++)     {         (int j = 0; j < col; j++)             {                 cout << setw(4) << array1[i][j];             }         cout << endl;     } cout << endl << endl << "in array 2 array2 = " << *array1;  return array1; 

}

the array seems populate input fine, when print ptr1 in main function, returns memory address , not number entered array.

any appreciated.

printing pointer print value of pointer. memory address. if want see value @ beginning of 2d array need dereference pointer.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -