Memory of an Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Memory of an Array

How much memory an Array can take (like integer 4 bytes)? is this varry through array data type??

9th May 2017, 3:20 PM
MUʜAMMED ɪʟʟYAS
MUʜAMMED ɪʟʟYAS - avatar
3 Answers
+ 7
Each element can be the size of whatever data type the array is. So each element would be 4 bits, if it is an int array. The size of the array determines how much total memory the array will/can use. As for the maximum amount of memory you can use, that'd probably be until you get an out of memory error.
9th May 2017, 3:27 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
memory of an array is no of total elements * size of integer each element in an int array has 4 bytes. ex int ar[10][10]; has memory 10 * 10 * 4 = 400 bytes
9th May 2017, 3:27 PM
MR Programmer
MR Programmer - avatar
+ 2
You mean how many elements you can store in an array? You can do it static: int array[5]; Or dynamic with allocating memory and extending it when you need to. But the easier version is to solve it the static way. Oh and for the size: it takes x times the size of the datatype you specify the array. so if you define the array "int array[5]" it would need 5 times the space of the datatype of int on your system.
9th May 2017, 3:28 PM
Patrick Schieber
Patrick Schieber - avatar