Created
February 16, 2015 12:38
-
-
Save yuanqing/8ef4a91042b56fdbe80e 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 arr[2] = { 1, 2 }; | |
int* x = &arr[0]; // x = address of arr[0] | |
printf("%d, %d\n", *x, arr[0]); //=> 1, 1 | |
arr[0] = 24; | |
printf("%d, %d\n", *x, arr[0]); //=> 24, 24 | |
*x = 42; | |
printf("%d, %d\n", *x, arr[0]); //=> 42, 42 | |
int* y = x + 1; // y = (address of arr[0]) + 1 = address of arr[1] | |
printf("%d, %d\n", *y, arr[1]); //=> 2, 2 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment