Functions

While main() is a function, it is an unusual one, because it is called automatically when you start your program. All other functions are called by your own code as the program runs.

A program is run line by line starting at the top of main, until another function is called. Control is then transferred to that function. When that function finishes, it returns control to the line after its call in main. If the function you call in turn calls another function, control flows in the same way—returning to the line in the first function that follows its call to the other function.

Even if a function is defined above main in the listing (you'll see this later), it is not performed before main. main always runs first.

Functions either return ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND 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.