7.4.1. Declaring an array and Using a Loop to Initialize the array’s Elements

The program in Fig. 7.3 declares five-element integer array n (line 10). Line 5 includes the <array> header, which contains the definition of class template array. Lines 13–14 use a for statement to initialize the array elements to zeros. Like other automatic variables, automatic arrays are not implicitly initialized to zero although static arrays are. The first output statement (line 16) displays the column headings for the columns printed in the subsequent for statement (lines 19–20), which prints the array in tabular format. Remember that setw specifies the field width in which only the next value is to be output.

 1   // Fig. 7.3: ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.