C - Pointers

author: Paul Kim

categories: c

tags: c

Pointers in C

One of the biggest challenges learning C is pointers. At first glance, it seems pretty obvious.

#include <stdio.h>

int main() {
  // an int
  int i = 1;

  // a pointer to an int
  int *pi;

  // pi points to i
  pi = &i;

  // print value of i
  printf("i = %d\n", i);

  // print address of i
  printf("&i = %p\n", &i);

  // dereference the address of i
  // to print the value of i
  printf("*(&i) = %d\n", *(&i));

  // print the address of pi
  printf("pi = %p\n", pi);

  // dereference pi and print it
  printf("*pi = %d\n", *pi);


© 2021 All rights reserved.