Skip to content

Instantly share code, notes, and snippets.

@daniel-vera-g
Last active April 10, 2020 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-vera-g/03bcfc9a39f16ca06a40906ff7b6221e to your computer and use it in GitHub Desktop.
Save daniel-vera-g/03bcfc9a39f16ca06a40906ff7b6221e to your computer and use it in GitHub Desktop.
c pointers explained.
#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