teach-ict.com logo

THE education site for computer science and ICT

3. Static arrays

There are two ways of determining the length of an array. The first is to define exactly how long the array can be, and not allow it to get any bigger or smaller while the program runs. This is called a static array.


A static array has a defined length which does not change.

The length of a static array is declared in advance, like this

                    array MyList[5]

This is declaring to the program that the array named MyList requires enough memory to store five items. Even when it is empty of any elements or values, it is still given the same amount of memory.

Declaring static arrays whenever you can is useful to compilers, as it helps the compiler set aside the correct amount of memory in the final executable file. It will also run faster than a dynamic array.


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: advantages of a static or dynamic array