Gotchas: Difference between revisions

Content added Content deleted
Line 170: Line 170:
<syntaxhighlight lang="C">int foo[4] = {4,8,12,16};</syntaxhighlight>
<syntaxhighlight lang="C">int foo[4] = {4,8,12,16};</syntaxhighlight>


However, arrays are zero-indexed, so in your code you'll never actually want to read from that subscript. Doing so indexes the array out of bounds, reading or writing the address of whatever happens to be stored in memory after it.
However, arrays are zero-indexed, so in your code you'll never actually want to read from/write to the same subscript used when declaring the array. Doing so indexes the array out of bounds, reading from or writing to the address of whatever happens to be stored in memory after it.


Chances are this will compile even though it's not something you really want to have happen.
Chances are this will compile even though it's not something you really want to have happen.