{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

5-Default Arguments - Default Arguments Default arguments...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Default Arguments // Default arguments are arguments that are passed to a function // regardless of whether or not the actual caller provides those // arguments int boxVolume(int length = 1, int width = 1, int height = 1); int getY(); #include <iostream> #define CONSTANT 25 using namespace std; // using the standard namespace will give us access // to things like cin & cout // default parameters can be mixed with regular parameters // Restriction, default arguments must exist as the last arguments // after any other arguments that do not have default values. //int incorrectDefault(int length = 1, int size); int correctDefault(int size, int length = 1); int constantDefault(int size, int width = CONSTANT); int functionDefault(int x, int y = getY()); int main (void) { cout << "call to boxVolume(): " << boxVolume() << "\ncall to boxVolume(5): " << boxVolume(5) << "\ncall to boxVolume(5, 5): " << boxVolume(5, 5) << "\ncall to boxVolume(5, 5, 5): " << boxVolume(5, 5, 5) << endl; cout << "\nSome others...\n" << "\ncorrectDefault()... Nope, needs size." //<< correctDefault() << "\ncorrectDefault(2) : " << correctDefault(2) << "\ncorrectDefault(2, 4) : " << correctDefault(2, 4) << "\nconstantDefault(5) : " << constantDefault(5)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}