C++ Programming - Functions - Discussion
Discussion Forum : Functions - General Questions (Q.No. 2)
2.
Which of the following statement is correct?
Discussion:
10 comments Page 1 of 1.
Matiyas ginbaru said:
2 years ago
Statement A: C++ enables defining functions that take constants as arguments.
In C++, you can declare function parameters as constants using the const keyword. This allows you to pass constant values or variables as arguments to the function.
Statement B: Functions that are declared with parameters as constants cannot modify the values of those parameters. When a function parameter is declared as const, it signifies that the function will not alter the value of the parameter. This restriction ensures that the function does not inadvertently modify the passed argument.
Therefore, both statements A and B are correct, so, the correct answer is C.
In C++, you can declare function parameters as constants using the const keyword. This allows you to pass constant values or variables as arguments to the function.
Statement B: Functions that are declared with parameters as constants cannot modify the values of those parameters. When a function parameter is declared as const, it signifies that the function will not alter the value of the parameter. This restriction ensures that the function does not inadvertently modify the passed argument.
Therefore, both statements A and B are correct, so, the correct answer is C.
(3)
Shiv said:
1 decade ago
Constant = The variable having fixed value is called as constant.
Hence, constant can not change their values.
And function takes variable as an argument.
Constant is a type of variable.
i.e. Option C is correct.
Hence, constant can not change their values.
And function takes variable as an argument.
Constant is a type of variable.
i.e. Option C is correct.
Bhaumik said:
1 decade ago
Its not change the argument type. We can change its value which type of argument is there. So arguments type is constant.
Prabhat said:
1 decade ago
If argument is constant. Then what is the need of having argument.
Function without argument can serve the purpose.
Function without argument can serve the purpose.
(1)
Sowmya said:
1 decade ago
Once the arguments are declared as constants that can't to change its value in any execution. Even in function.
Aleyan said:
1 decade ago
Constant can not change their values and if argument is constant we can not change argument value.
TvdZ said:
1 decade ago
Technically B is incorrect, as a const_cast would allow you to change a constant.
Hari said:
1 decade ago
If arguments fixed as constants that can not be changed.
Navya said:
10 years ago
Why we cannot use the constant while defining function?
(1)
Samala sumanth said:
8 years ago
Can mutable change the value of const?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers