Last active
April 10, 2020 19:48
-
-
Save daniel-vera-g/03bcfc9a39f16ca06a40906ff7b6221e to your computer and use it in GitHub Desktop.
c pointers explained.
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
#include <stdio.h> | |
int main() { | |
int* p; | |
// Address pointer is pointing to | |
printf("Address pointer p is pointing to: %p\n", p); | |
// Address of pointer itself | |
printf("Address of pointer p itself: %p\n", &p); | |
int x = 3; | |
printf("Initialized int x: %d\n", x); | |
p = &x; | |
printf("Initialized pointer p with x: %d\n", *p); | |
// Address pointer is pointing to | |
printf("Address of int x: %p\n", &x); | |
printf("Address pointer p is pointing to: %p\n", p); | |
// Address of pointer | |
printf("Address of pointer p itself: %p\n", &p); | |
// Value of adress pointer is pointing to | |
printf("Value of int x: %d\n", x); | |
printf("Value of adress pointer is pointing to: %d\n", *p); | |
// Change value of x | |
*p = 1; | |
printf("Value of int x now: %d and value pointer is pointing to also: %d", x, *p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment