In C++, const qualifier can be applied to
1) Member functions of a class
2) Function arguments
3) To a class data member which is declared as static
4) Reference variables
(A) Only 1, 2 and 3
(B) Only 1, 2 and 4
(C) All
(D) Only 1, 3 and 4
Answer: (C)
Explanation: When a function is declared as const, it cannot modify data members of its class.
When we don’t want to modify an argument and pass it as reference or pointer, we use const qualifier so that the argument is not accidentally modified in function.
Class data members can be declared as both const and static for class wide constants.
Reference variables can be const when they refer a const location.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C++ | const keyword | Question 3
- C++ | const keyword | Question 5
- C++ | const keyword | Question 5
- C++ | const keyword | Question 1
- Function overloading and const keyword
- Difference between const int*, const int * const, and int const *
- Difference between const char *p, char * const p and const char * const p
- C++ | Static Keyword | Question 1
- C++ | Static Keyword | Question 2
- C++ | Static Keyword | Question 4
- C++ | Static Keyword | Question 6
- C++ | Static Keyword | Question 5
- C++ | Static Keyword | Question 3
- C++ | friend keyword | Question 1
- C++ | friend keyword | Question 2
- Const Qualifier in C
- Diffference between #define and const in C?
- How to modify a const variable in C?
- Why copy constructor argument should be const in C++?
- “static const” vs “#define” vs “enum”

