-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_dim_arrays_20.cpp
39 lines (38 loc) · 1.08 KB
/
two_dim_arrays_20.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//size of an mxn array
#include <iostream>
using namespace std;
int main()
{
int m, n;
cout << "Enter size of Matrix : " << endl;
cin >> m >> n;
int arr[m][n];
int arraySize = sizeof(arr);
int getArrayLength = sizeof(arr) / sizeof(arr[0]);
cout << "Size of array is : " << arraySize << "bytes" << endl;
cout << "getArrayLength is : " << getArrayLength << endl;
cout << endl;
return 0;
}
/*****************************
* size of an array
* for 1 row/column
* sizeof(arr) = 4[size of int = 4]/ or we can say 4*1
* for 2 row/column
* sizeof(arr) = 8 (4+4) [size of int = 4] / or we can say 4*2
* for 3 row/column
* sizeof(arr) = 12 (4+4+4) [size of int = 4]/ or we can say 4*3
* etc.......
*
* Similarly ,Array Length
* sizeof(arr[0]) = 4 [size of int = 4]
* Hence size:
* size = sizeof(arr) / sizeof(arr[0]);
* for 1 row/column:
* size = 4 /4 = 1
* for 2 row/column:
* size = 8 /4 = 2
* for 3 row/column:
* size = 12 /4 = 3
* etc.......
* ****************************************************************/