CHAPTER 7

image

Arrays

An array is a data structure used for storing a collection of values that all have the same data type.

Array Declaration and Allocation

To declare an array you start as you would a normal variable declaration, but in addition append a set of square brackets following the array’s name. The brackets contain the number of elements in the array. The default values for these elements are the same as for variables – elements in global arrays are initialized to their default values and elements in local arrays remain uninitialized.

int myArray[3]; // integer array with 3 elements

Array Assignment

To assign values to the elements you ...

Get C++ 14 Quick Syntax Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.