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