2d array memory use (quiz question)

Feb 6, 2013 at 3:57am
how do you figure how many bytes a array of float arr[8],[8] uses this was a question i can not find the formula or answer to , I thought you times the 8*8*
4 (bytes per float ) but that is not right. Some help on how to figure memory used on this array of floats would be greatly appreciated.
Feb 6, 2013 at 3:59am
The sizeof operator is your friend ;-)
Feb 6, 2013 at 4:24am
yeah i used that to find the answer but is there a math formula based on the size of the array with the type used (float, int, char) ?
Feb 6, 2013 at 4:46am
Yes, arrays are tightly packed, which means you can use the formula you originally thought - 8 * 8 * 4, but that's assuming a 4-byte float, which isn't necessarily the case.

The formula you want for an array float arr[8][8] is 8 * 8 * sizeof(float)

But sizeof(arr) is best ;-)

Cheers,
Jim
Feb 6, 2013 at 2:02pm
Thanks that what i was doing but must have fat finger the calculator and got the wrong answer. Perfect that is what i was looking for.
Topic archived. No new replies allowed.