InterviewSolution
| 1. |
What do you understand by default arguments and constant argument? Write a short note on their usefulness. |
|
Answer» Default arguments: C++ allows us to assign default values to a function’s parameters which are useful in case a matching argument is not passed in the function call statement. The default values are specified at the time of function declaration. Example: float interest(float principal, int time, float rate=0.10); Constant argument: By constant argument, it is meant that the function cannot modify these arguments. In order to make an argument constant to a function, we can use the keyword const as shown : int sum (const int a, const int b); The qualifier const in function prototype tells the compiler that the function should not modify the argument. The constant arguments are useful when functions are called by reference. |
|