<<< Address of a C++ variable     Index     Pointer to a C++ variable >>>

3. Storing address of a variable

  • Could we store an addresses of variables in our program?

    
    int main( )
    {
        int x = 5;
        double d = 0.1;
    
        // Variable sizes:
        int x_bytes = sizeof( x );
        int d_bytes = sizeof( d );
    
        // Take and store variable addresses:
        int x_addr = &x;
        int d_addr = &d;
    
        return 0;
    }
    
    
  • But why the code does not compile?..

    • ...because an address needs a special type of storage!

<<< Address of a C++ variable     Index     Pointer to a C++ variable >>>