Skip to content

Instantly share code, notes, and snippets.

@yuanqing
Created February 16, 2015 12:38
Show Gist options
  • Save yuanqing/8ef4a91042b56fdbe80e to your computer and use it in GitHub Desktop.
Save yuanqing/8ef4a91042b56fdbe80e to your computer and use it in GitHub Desktop.
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