Created
January 25, 2018 14:15
-
-
Save shailrshah/927fb2b209bbb244637bf6958b33d670 to your computer and use it in GitHub Desktop.
Basics about Pointers
This file contains hidden or 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
#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