5-Default Arguments

5-Default Arguments - / Default Arguments / Default...

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 // 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"
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Page1 / 2

5-Default Arguments - / Default Arguments / Default...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online