Introduction to Pointers in C

Introduction to Pointers in C


Introduction

Pointers are one of the most powerful and important concepts in C programming.

👉 A pointer is a variable that stores the address of another variable.


What is a Pointer?

A pointer is:
👉 A variable that stores memory address


Why Use Pointers?

  • ✔ Efficient memory usage
  • ✔ Dynamic memory allocation
  • ✔ Used in arrays, functions, structures
  • ✔ Faster program execution

Declaration of Pointer

data_type *pointer_name;

Example

int *ptr;

Initialization of Pointer

int a = 10;
int *ptr = &a;

👉 & → Address of operator


Accessing Value Using Pointer

printf("%d", *ptr);

👉 * → Dereference operator (value at address)


Example Program

#include <stdio.h>

int main() {
int a = 10;
int *ptr;

ptr = &a;

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

return 0;
}

Output

Value of a = 10
Address of a = (memory address)
Pointer value = (same address)
Value using pointer = 10

Key Operators

Operator Meaning
& Address of variable
* Dereference (value at address)

Pointer and Variable Relationship

👉 Example:

int a = 5;
int *ptr = &a;
  • a → value = 5
  • &a → address of a
  • ptr → stores address
  • *ptr → value at address (5)

Important Points

  • Pointer must be initialized
  • Always use correct data type
  • Uninitialized pointer → garbage value

Common Mistakes

  • ❌ Using pointer without initialization
  • ❌ Confusing * and &
  • ❌ Wrong data type pointer
  • ❌ Dereferencing NULL pointer

Pro Tips

  • ✔ Practice pointer basics
  • ✔ Understand memory clearly
  • ✔ Use pointers carefully
  • ✔ Learn pointer with arrays

Conclusion

Pointers are a core concept in C programming. They give direct access to memory and improve performance.

Mastering pointers will take your programming skills to the next level.

👉 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