Bytes in multidimensional arrays

Hey, i'm wondering how you find out how many bytes are used in multidimensional arrays. I've been looking in my book, but I can't find it. I was thinking that you just multiply the rows by the columns...

float nums[10][10]; I know that a float takes up 4 bytes.
I know that a float takes up 4 bytes.

On your computer - but not necessarily on others.

The easiest way is sizeof(nums)
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>

int main()
{
	float array;
	std::cout << sizeof(array) << std::endl;
	
	float array1[10];
	std::cout << sizeof(array1) << std::endl;
	
	float array2[10][10];
	std::cout << sizeof(array2) << std::endl;
		
	return 0;
}
4
40
400
 
Exit code: 0 (normal program termination)


The above sizes are in bytes and there are 10 rows x 10 columns = 100 elements in the OP nums array. 4 bytes per integer element giving 400 bytes allocated for the array.
Last edited on
Okay thanks guys that's how i thought it was done.
Topic archived. No new replies allowed.