Program Notes
First, the program in Listing 4.1 creates a three-element array called yams
. Because yams
has three elements, the elements are numbered from 0
through 2
, and arrayone.cpp
uses index values of 0
through 2
to assign values to the three individual elements. Each individual yam
element is an int
with all the rights and privileges of an int
type, so arrayone.cpp
can, and does, assign values to elements, add elements, multiply elements, and display elements.
The program uses the long way to assign values to the yam
elements. C++ also lets you initialize array elements within the declaration statement. Listing 4.1 uses this shortcut to assign values to the yamcosts
array:
int yamcosts[3] = {20, 30, 5};
It simply provides a comma-separated ...
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.