Skip to content

Instantly share code, notes, and snippets.

@kasramp

kasramp/test.cpp Secret

Created August 1, 2020 23:24
Show Gist options
  • Save kasramp/29db39dbf57a3bb7663ac8e5a306b44b to your computer and use it in GitHub Desktop.
Save kasramp/29db39dbf57a3bb7663ac8e5a306b44b to your computer and use it in GitHub Desktop.
int main(int argc, char *argv[]) {
int *p;
int x = 20;
int y = 10;
p = x; // compile error
p = &x;
int *pp = &y; // pp points to y, *pp value is equal to 10 and pp holds y address
int **ppp; // making pointer which points to another pointer
cout << *p << endl; // prints 20
ppp = &p;
cout << *ppp << endl; // prints 20
cout << p << endl; // prints x address
cout << &p << endl; // prints p address
p++; // increases current p address 2 bytes (ints)
*p++; // increases the value of x
++*p; // increases the value of x
*p = y; // value of y will be copied to p, so x will be changed to 10
*p = &y; // address of y will be copied to p, so x will be changed to y address
p = &y; // p points to y
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment