May 2012
Intermediate to advanced
679 pages
16h 56m
English
C++ supports functions with default arguments. When we define a function, it is possible to define initial values for parameters. Consider function increment. If we want to write function increment to increase the value of a variable by any other value, we can define the function increment as:
void inc(int &x, int y) { x = x + y ; };
This will increment variable x by value y. However, most of the time in programming we have to increment value by 1. If we pass the value 1 as a default value to parameter y, the function can be redefined as follows:
void inc(int &x, int y=1) {x = x + y};
If we call function as inc(marks,5) ;
Variable marks will be incremented by 5. If we call inc(marks); Variables marks ...
Read now
Unlock full access