Double Pointers in C

Double Pointers in C


Introduction

A double pointer is a pointer that stores the address of another pointer.

👉 It is also called:

  • Pointer to pointer
  • Two-level pointer

What is a Double Pointer?

A double pointer is:
👉 A pointer that points to another pointer


Declaration of Double Pointer

data_type **pointer_name;

Example

int **ptr;

Initialization of Double Pointer

#include <stdio.h>

int main() {
int a = 10;

int *p = &a;
int **dp = &p;

printf("Value of a = %d\n", a);
printf("Using pointer = %d\n", *p);
printf("Using double pointer = %d\n", **dp);

return 0;
}

Output

Value of a = 10
Using pointer = 10
Using double pointer = 10

Understanding Levels

Expression Meaning
a Value
&a Address of a
p Stores address of a
*p Value of a
dp Stores address of p
*dp Address of a
**dp Value of a

Double Pointer Table (Styled)

Expression Meaning
dp Pointer to pointer
*dp Pointer
**dp Value

Example: Changing Value Using Double Pointer

#include <stdio.h>

void change(int **ptr) {
**ptr = 50;
}

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

change(&p);

printf("Value of a = %d", a);

return 0;
}

Output

Value of a = 50

Real-World Uses

  • Dynamic memory allocation
  • Arrays of pointers
  • Multi-level data structures
  • Passing pointer to functions

Important Notes

  • Use correct number of *
  • Initialize pointers properly
  • Understand pointer levels

Common Mistakes

  • ❌ Confusing * and **
  • ❌ Wrong declaration
  • ❌ Uninitialized pointer
  • ❌ Misunderstanding pointer levels

Pro Tips

  • ✔ Practice pointer levels
  • ✔ Visualize memory
  • ✔ Use simple examples first
  • ✔ Combine with functions

Conclusion

Double pointers are advanced but powerful concepts in C. They allow deeper control over memory and are useful in complex programs.

Master them to become strong in C programming.

👉 This article is part of Dharani Tech Edu Hub — where learning programming is made simple and practical.

Comments

Popular posts from this blog

Introduction to C Programming

Operators in C

Input & Output in C