What I think Consts is used for

Good Day everyone. What I think const is use for in your code is to fix the errors in your code and make the wrong codes right.


Ernest Dinsdale

const can be used to prevent modification to a variable.
For example: const int a ;
if we declare like this in our programe ,then the value of variable “a” will be fixed i.e unchangeable.

1 Like

It does depend on how you use the keywork ‘const’. If it is just before declaring a variable like 'const Item m_items" than m_items can’t be modify member variables(just non-mutable variables) and call non-const member functions. if is just after the member function signature that states that function does not modify the state of the object and is safe to allow const objects to call this function. There are few more uses that the keyword const have, most of them are very advance uses(like related to rvalues,lvalues)

1 Like

Privacy & Terms