KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was reading my C++ book (Deitel) when I came across a function to calculate the volume of a cube. The code is the following: double cube (const double side){ return side * side * side; } The explanation for using the "const" qualifier was this one: "The const qualified should be used to enforce the principle of least privilege, telling the compiler that the function does not modify variable side". My question : isn't the use of "const" redundant/unnecessary here since the variable is being passed by value, so the function can't modify it anyway?
Tags (comma-separated)
Save Edits
Cancel