top of page
Arrays
Arrays in C work by providing us an organized method to input and assign values to numerically defined slots. These slots range from 0 to however big the array is.
To declare an array we will use the syntax: arrType arrName[size];
For example an array of 50 integers can be defined as: int arr[50];
Output:

Example:

To initialize and provide value to a piece of an array we use: arrName[no.] = value;
Since arr[2] was not given a value the output is unexpected. For this reason, it is sometimes good to set the contents of an array to 0 before working with them. Also notice how we stat with arr[0] not arr[1]. If the array were to be printed out in its entirety then 48 of its 50 slots will result in unexpected numbers, To mitigate this we may add the Null Terminator which signals the end of the array. The Null Terminator can be entire as \0 and takes up one character-sized slot in an array.
While working with large arrays it is common practice to assign and output data automatically using loops. Let's make a program which will produce multiples of 5 up to 250.
Example:

Output:

bottom of page