C Programming Tutorial
Computer Tutorial

Array Elements in Memory

Array Elements in Memory

When we declare an array in C, they can reserved the memory immediately as per there size.

Eg- int arr[8] ;
It can reserved 16 bytes in memory, 2 bytes each for the 8 integers (under Windows/Linux the array would occupy 32 bytes as each integer would occupy 4 bytes). And since the array is not being initialized, all eight values present in it would be garbage values. This so happens because the storage class of this array is assumed to be auto. If the storage class is declared to be static then all the array elements would have a default initial value as zero.

Diagram to show the functionality of The for loop

Arrangement of array elements in memory

Remember the following things about Array

» An array is a collection of similar elements.
» The first element in the array is numbered 0, so the last element is 1 less than the size of the array.
» An array is also known as a subscripted variable.
» Before using an array its type and dimension must be declared.
» However big an array its elements are always stored in contiguous memory locations. This is a very important point which we would discuss in more detail later on.