Pointers in C

A pointer is a variable that stores the memory address of another variable instead of a direct value. Pointers help in efficient memory management and advanced programming.

Why Use Pointers?

Basic Example


#include <stdio.h>

int main() {
    int a = 10;
    int *p = &a;

    printf("Value of a: %d\n", a);
    printf("Address of a: %p\n", &a);
    printf("Pointer value: %p\n", p);
    printf("Value using pointer: %d\n", *p);

    return 0;
}

Expected Output

Value of a: 10 Address of a: 0x7ffd... Pointer value: 0x7ffd... Value using pointer: 10

Pointer to Pointer


int a = 5;
int *p = &a;
int **pp = &p;

printf("%d", **pp);

Output

5

Common Mistakes