C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 31)
31.
Which of the following is the correct way of declaring a function as constant?
const int ShowData(void) { /* statements */ }
int const ShowData(void) { /* statements */ }
int ShowData(void) const { /* statements */ }
Both A and B
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Vls said:   2 years ago
Here, It asks about a function, not a member function or method. Constness of a standalone function doesn't make sense.

Amit Shahi said:   8 months ago
Here the question is how to declare the function as a constant that's why the C option is the right answer.

If the question is asking how to declare a function return as a constant then the D option is the right answer.

Dimpi said:   6 months ago
D option is the right one.

Because both A and B options correctly define the function, it returns a const int.


Post your comments here:

Your comments will be displayed after verification.