R
Rishtaara
C Programming Fundamentals
Lesson 5 of 8Article18 min

Pointers Fundamentals

Pointers store memory addresses. The '&' operator gets an address and '*' dereferences it to access the value at that address.

Addresses and dereferencing

Pointers store memory addresses. The '&' operator gets an address and '*' dereferences it to access the value at that address.

Pointer basics
#include <stdio.h>

int main(void) {
    int value = 25;
    int *ptr = &value;

    printf("value=%d\n", value);
    printf("address=%p\n", (void*)ptr);
    printf("dereference=%d\n", *ptr);
    return 0;
}

Pointer safety tips

  • Initialize pointers before dereferencing.
  • Avoid returning pointers to local stack variables.
  • Set freed pointers to NULL to reduce accidental reuse.