C++ Variable Declaration Keywords const

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A type specifier; when applied to a type, produces the const-qualified version of the type. See const keyword for details on the meaning of const.

const int x = 123;
x = 456;    // error
int& r = x; // error

struct S {
    void f();
    void g() const;
};
const S s;
s.f(); // error
s.g(); // OK


Got any C++ Question?