Initializing a Two-Dimensional Array
When you create a two-dimensional array, you have the option of initializing each element. The technique is based on that for initializing a one-dimensional array. Remember that you do this by providing a comma-separated list of values enclosed in braces:
// initializing a one-dimensional arrayint btus[5] = { 23, 26, 24, 31, 28};
For a two-dimensional array, each element is itself an array, so you can initialize each element by using a form like that in the previous code example. Thus, the initialization consists of a comma-separated series of one-dimensional initializations, all enclosed in a set of braces:
int maxtemps[4][5] = // 2-D array{ {96, 100, 87, 101, 105}, // values for maxtemps[0] {96, ...
Get C++ Primer Plus 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.