Prototyping and Calling a Function

By now you are familiar with making function calls, but you may be less comfortable with function prototyping because that’s often been hidden in the include files. Listing 7.2 shows the cheers() and cube() functions used in a program; notice the function prototypes.

Listing 7.2. protos.cpp

// protos.cpp -- using prototypes and function calls#include <iostream>void cheers(int);       // prototype: no return valuedouble cube(double x);  // prototype: returns a doubleint main(){    using namespace std;    cheers(5);          // function call    cout << "Give me a number: ";    double side;    cin >> side;    double volume = cube(side);    // function call    cout << "A " << side <<"-foot cube has a volume of "; ...

Get C++ Primer Plus 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.