4. Functions: Many Are Called

The most fundamental building block in the programming toolkit is the function—often known as procedure or subroutine in other languages. A function is a group of related statements that accomplish a specific task. Once you define a function, you can execute it whenever you need to do so.

Understanding functions is a crucial step to programming in C++: Without functions, it would be a practical impossibility to engage in serious programming projects. Imagine how difficult it would be to write a word processor, for example, without some means of dividing the labor. Functions make this possible.

The Concept of Function

If you’ve followed the book up until this point, you’ve already seen use of a function—the sqrt

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second Edition now with O’Reilly online learning.

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