Skip to content

Instantly share code, notes, and snippets.

@shailrshah
Created January 25, 2018 14:15
Show Gist options
  • Save shailrshah/927fb2b209bbb244637bf6958b33d670 to your computer and use it in GitHub Desktop.
Save shailrshah/927fb2b209bbb244637bf6958b33d670 to your computer and use it in GitHub Desktop.
Basics about Pointers
#include <stdio.h>
int main() {
int foo = 1994;
// let pFoo be a pointer that points to an integer variable, whose value is the address of foo
int* pFoo = &foo;
printf("pFoo = &foo = %p = %p\n", pFoo, &foo);
// go to the variable pFoo points to (foo) and get its value. This is called dereferencing pFoo.
printf("*pFoo = foo = %d = %d.\n", *pFoo, foo);
printf("&pFoo != &foo (%p != %p)\n", &pFoo, &foo);
return 0;
}
/* Output:
pFoo = &foo = 0061FF2C = 0061FF2C
*pFoo = foo = 1994 = 1994.
&pFoo != &foo (0061FF28 != 0061FF2C)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment