Arrays in C
Source: samek-embedded
- Group of variables of the same type.
- The variables occupy consecutive memory locations.
- An array is treated as a pointer (to the beginning of the array). Likewise, every pointer can also be viewed as an array.
|
|
- Indexing the array is equivalent to adding the index to the array pointer and getting the value at that address.
- The value
counter[1]
is equivalent to*(counter + 1)
(pointer arithmetic)
Address arithmetic vs. pointer arithmetic
From the LED example :
|
|
In address arithmetic:
- address is calculated
- then cast to a pointer type
- the pointer value is set via the dereferenced pointer