Can the default value of a parameter be an expression?
- No, it must be a constant value
- No, it must be a string
- Yes, but only for pointer parameters
- Yes, it can be any valid expression
In C++, the default value of a function parameter can indeed be an expression. This expression can be any valid C++ expression, providing flexibility when setting default values. It's not limited to constant values and can include calculations or other expressions.
Loading...
Related Quiz
- John is writing a function to concatenate two strings. He wants the function to add a space between the strings by default but also wants to give the user the option to specify their own separator. Which feature of C++ can help him?
- Considering cache efficiency, which STL container will provide the fastest element access and iteration in most cases?
- Some compilers detect tail recursion and optimize it through a technique known as _______.
- Which type of inheritance in C++ restricts a derived class from inheriting from more than one base class?
- If no cases match in a switch statement and there's no default clause, then none of the switch blocks will execute.