O'Reilly logo

C++ Primer Plus by Stephen Prata

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

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

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