Gotchas: Difference between revisions

No edit summary
Line 166:
 
if(a==b){} //runs the code in the curly braces if and only if the value of "a" equals the value of "b".</syntaxhighlight>
 
===Arrays===
Arrays are declared with the total number of elements in an array.
<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.
<syntaxhighlight lang="C">int foo[4] = {4,8,12,16};
int x = foo[0]; //x = 4
int y = foo[3]; //y = 16
int z = foo[4]; //z = ?????????</syntaxhighlight>
 
=={{header|J}}==
1,489

edits