Type Aliases Simplify Pointers to Multidimensional Arrays

A type alias (§ 2.5.1, p. 67) can make it easier to read, write, and understand pointers to multidimensional arrays. For example:

using int_array = int[4]; // new style type alias declaration; see § 2.5.1 (p. 68)typedef int int_array[4]; // equivalent typedef declaration; § 2.5.1 (p. 67)// print the value of each element in ia, with each inner array on its own linefor (int_array *p = ia; p != ia + 3; ++p) {    for (int *q = *p; q != *p + 4; ++q)         cout << *q << ' ';    cout << endl;}

Here we start by defining int_array as a name for the type “array of four ints.” We use that type name to define our loop control variable in the outer for loop.

Exercises Section 3.6

Exercise 3.43: ...

Get C++ Primer, Fifth 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.