Chapter 6. Using Arrays

<feature>
  • Learn how to define and initialize an array

  • Learn how to access array elements

  • See how to use loops with arrays

  • Find and replace text and formatting

  • Learn to use multi-dimensional arrays

</feature>

Why Use Arrays?

With the exception of character strings, the data types and variables you’ve seen up to this point have been simple data types that store only a single value. Consider these two variables:

char ch = 'B';
int num = 134;

Variables like these are called scalar variables. They can contain only a single value at a time, and you can’t subdivide them further; they are elemental. An array is a group of variables having the same data type.

In writing efficient programs, it’s often convenient to have an array of variables ...

Get Practical C++ 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.