How to make reference to variables (c++) -


these global variables:

const int maxrow = 5; const int maxcol = 5; int a[maxrow][maxcol] = { 0 }; int newarr[maxrow + 1][maxcol + 1] = { 0 }; 

how declare them in main , use them in these functions:

void case1() { (int r = 0; r < maxrow; ++r)     (int c = 0; c < maxcol; ++c) {         cout << "\n a[" << r << "][" << c << "]= ";         cin >> a[r][c];      }  }  void case2() {      int max[maxcol] = { 0 };      (int r = 0; r < maxrow; ++r) {         int minr = a[r][0];     ..............................      } void case3() {     int negnumber = 0;     double average = 0;      (int r = 0; r < 6; ++r) {         (int c = 0; c < 6; ++c) {             .............. if (newarr[r][c] < 0) {                 ++negnumber;                 average += newarr[r][c]; 

i using while menu. how can easily.

you can declare local variables in main() in same way did in case3() negnumber , average.

passing variables functions pretty easy. need define input parameters function. this: case1( int var1 ). can use var1 in function case1 , have call case1 arguments passed in. this: case1( 2 ).

you can find solution case (passsing 2d arrays funtions) here: passing 2d array c++ function

read more funtions in c++ here: https://msdn.microsoft.com/en-us/library/c4d5ssht.aspx


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -