First page Back Continue Last page Graphics
Array Usage
Common Array Usage is to:
- initialize all the elements to a certain number
- do some work or math to set the values of the elements
- mabey sort the numbers and swap element positions ...
Access and element from the array by using the brackets:
- “numbers[100]” accesses the 99th element in numbers since the first element is 0 not 1
- NEVER try to access an element outside of the list aka if number has 100 elements, don't try to access numbers[200] or numbers[-1], your program will crash with a “segmentation fault”
In order to access all the elements easily, the for loop is your friend: