Quick actions

cmd+k|ctrl+k

Navigation

Languages

p = &x versus *p = x

Snippet info

Language

Cpp

Visibility

public

Author

slim

Created

2017-11-16T19:17:44Z

Updated

2017-11-16T19:17:44Z

#include <iostream>
using namespace std;

int main() {
    int x = 1;
    int y = 2;
    int* p;
    cout << "&x is: " << &x << endl;
    cout << "&y is: " << &y << endl << endl;
    
    p = &x;
    cout << "p is: " << p << endl;
    cout << "&x is: " << &x << endl;
    cout << "&y is: " << &y << endl;
    cout << "*p is: " << *p << endl;
    cout << "x is: " << x << endl;
    cout << "y is: " << y << endl << endl;
    
    p = &y;
    cout << "p is: " << p << endl;
    cout << "&x is: " << &x << endl;
    cout << "&y is: " << &y << endl;
    cout << "*p is: " << *p << endl;
    cout << "x is: " << x << endl;
    cout << "y is: " << y << endl << endl;
    
    *p = x;
    cout << "p is: " << p << endl;
    cout << "&x is: " << &x << endl;
    cout << "&y is: " << &y << endl;
    cout << "*p is: " << *p << endl;
    cout << "x is: " << x << endl;
    cout << "y is: " << y << endl << endl;
    
    return 0;
}

// p is: 0x7ffdbae3a564
// *p is: 2
// x is: 1
INFO