+ 3
sizeof Multi Dimensional array?
like double arr[5][8]; cout << sizeof(arr) << endl; how is that calculated?
3 Respostas
+ 5
it's just multiplication like the times tables from grade school. we can take it apart piece by piece though. let's say we have int arr[5][4];
so sizeof (arr) would be 80. let's go further
sizeof (arr [5]) would be 16. this is essentially saying what is the size of the entire fifth column.
let's continue
sizeof (arr [5][4]) would be 4. and this is where you answer is(well kinda). it's 4 because it's essentially saying what is the size of the value in this specific location. well this is just an array, so it's a collection of variables of a data type. I'm our case it's an int, which is 4 bytes. so when we say what is the sizeof a multi dimensional array we can calculate it by doing (primitive data type size * dimension size 1 * dimension size 2 *...dimension size n-1 * dimension size n).
+ 4
it is equal to row*column*data type allocated memory
for example data type of int is 2
ex:int arr[5][2];
size=5*2*2
that equals to 20
size of the array allocated is 20
0
sizeof(any_multidimensional_array) = #of_elements * sizeof(arrayDataType)
#of_elements = first_dimension_size * second_dimension_size * third_dimen...