O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition by Brian Overland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required