Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C++ | const keyword | Question 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads