Skip to Main Content
C++ Primer Plus, Fourth Edition
book

C++ Primer Plus, Fourth Edition

by Stephen Prata
November 2001
Beginner content levelBeginner
1128 pages
29h 12m
English
Sams
Content preview from C++ Primer Plus, Fourth Edition

Functions and Arrays

So far the example functions have been simple, using only the basic types for arguments and return values. But functions can be the key to handling more involved types, such as arrays and structures. Let's take a look now at how arrays and functions get along with each other. Suppose you use an array to keep track of how many cookies each person has eaten at the family picnic. (Each array index corresponds to a person, and the value of the element corresponds to the number of cookies that person ate.) Now you want the total. That's easy to do; just use a loop to add all the array elements. But adding array elements is such a common task that it makes sense to design a function to do the job. Then, you won't have to write ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ Primer Plus, Fifth Edition

C++ Primer Plus, Fifth Edition

Stephen Prata
C++ All-In-One For Dummies®, 2nd Edition

C++ All-In-One For Dummies®, 2nd Edition

John Paul Mueller, Jeff Cogswell
C++ Primer Plus

C++ Primer Plus

Stephen Prata

Publisher Resources

ISBN: 0672322234Purchase book