Arrays
Syntax of defining an array: int a[10]; /* array of 10 integers */
In C the index starts from 0, so the above definition allocated 10 integer variables:a[0], … , a[9]
There is no allocated integer a[10] !!!!!However, the compiler will not warn you if you try to access it:int a[10];a[10] = 1; /* crush and burn !! */
To initialize an array you can use:a = {1,2,3,4,5,6,7,8,9,10}; /* a[0] == 1 */
Multidimensional arrays are defined as follows: int a[10][20]; /* a is array of 10 rows and 20 columns */a = {{1,1,… ,1}, {2,2,… ,2}, … {10,…,10}};ora = {1,1,… 1, 2,2,… ,2, … ,10, … ,10};
more on multidimensional arrays later