·  C++ – Syntax – Collections – Array

 

- Info:

  - Array index is positive integer that starts at 0.

  - Size of the array is fixed and it is part of its type.

 

- Create Array

  - int     array[3];              //Declared. Used to define scope.

  - int     array[3] = {0, 1, 2};  //Declared, memory reserved, elements added.

  - int     array[ ] = {0, 1, 2};  //Declared, memory reserved, elements added.

  - char    array[ ] = "Hello";

  - char    array[6] = "Hello";    //5+1 (zero terminated)

 

- Add Element:

  - array[0] = 5;                  //Add value 5 at index 0.

 

- Get Element:

  - int     element = array[0];    //Get element at index 0.

 

- Statistics:

  - int     length  = sizeof(array)/sizeof(array[0]);