C++ | const keyword | Question 2
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
(D) Only 1, 3 and 4
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!