-
-
Save kasramp/29db39dbf57a3bb7663ac8e5a306b44b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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