2.2.3 Default Values with a Prototype

Recall that a prototype is an advanced declaration of a function. You saw earlier that prototype needs to have the same function header. While that is still true, the one clarification to that is that you only define default values in the prototype.

// Define the default value here
double pow(double base, int exp = 2);

int main() { // Some code }

// Do not define the default value here
double pow(double base, int exp){
        // Some Code
}

The function definition still needs to have the same parameters and the same order, but you do not list the default value a second time.

Last updated