Pointers to static member variables

suggest change

A static member variable is just like an ordinary C/C++ variable, except with scope:

So, if you have access to the static member variable and decorate it correctly, then you can point to the variable like any normal variable outside a class:

class Class {
    static int i;
}; // Class

int Class::i = 1; // Define the value of i (and where it's stored!)

int j = 2;   // Just another global variable

int main() {
    int k = 3; // Local variable

    int *p;

    p = &k;   // Point to k
    *p = 2;   // Modify it
    p = &j;   // Point to j
    *p = 3;   // Modify it
    p = &Class::i; // Point to Class::i
    *p = 4;   // Modify it
} // main()

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents