5. Functions: Many Are Called

Programmers and computer scientists talk about creating reusable code, the Holy Grail of software development. There are many tools designed with this goal in mind. But the function (called a procedure or subroutine in other languages) is the most basic tool of all.

The function—which in C++ may or may not return a value—is based on this simple idea: once someone figures out how to accomplish a specific task, such as calculating a square root, you shouldn’t have to figure it out again.

So, instead of writing the same lines of programming code over and over, you write the function just once, and then execute it whenever you want to perform the desired task. This is known as “calling” a function.

In short, functions ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition 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.