C Pointers

C Tutorial

 C Pointers (Complete Tutorial: Beginner → Advanced)

Pointers are one of the most powerful and important concepts in C.
They allow direct memory access, efficient function calls, dynamic memory, and are heavily used in DSA, OS, Embedded systems, and interviews.

 What is a Pointer?

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

Example

  • a → normal variable

  • &a → address of a

  • p → pointer storing address of a

  • *p → value at that address (10)

 Why Pointers Are Needed?

  •  Direct memory access
  •  Call by reference
  •  Efficient array & string handling
  •  Dynamic memory allocation
  •  Data structures (Linked List, Tree)

 Pointer Declaration Syntax

Examples

 Pointer Initialization

Never use uninitialized pointers

int *p; // dangerous 

Dereferencing Pointer (* Operator)


 

  • *p gives value stored at address

 Pointer and Address Example (Memory View)

ExpressionMeaning
aValue (10)
&aAddress
pAddress of a
*pValue at address (10)

 Pointer Arithmetic


 

  •  Pointer moves by size of data type

Pointers and Arrays (Very Important)


 

  •  Array name itself is a pointer to first element

Pointer to Pointer (**)


 

  •  Used in dynamic memory & 2D arrays

Call by Reference Using Pointer


 

  •  Original variable is modified

 Pointers with Functions (Function Pointer Intro)


 

  • fp stores function address

 NULL Pointer

  •  Points to nothing
  • Used to avoid garbage access

 Dangling Pointer


 

  •  Avoid accessing freed memory

Void Pointer (void *)


 

  •  Generic pointer
  • Used in libraries (malloc, qsort)

 Pointers and Dynamic Memory (Preview)

  •  Heap memory management

 Common Pointer Mistakes

  •  Uninitialized pointer
  •  Dereferencing NULL pointer
  •  Forgetting &
  •  Memory leak (missing free)
  •  Confusing * and &

 Interview Questions (Must Prepare)

  1. What is a pointer?

  2. Difference between * and &

  3. Pointer vs array

  4. What is NULL pointer?

  5. What is dangling pointer?

  6. What is void pointer?

  7. Call by value vs call by reference

 Real-Life Use Cases

  • Dynamic memory allocation

  • Data structures (Linked List, Tree)

  • Embedded systems

  • OS kernels

  • Function callbacks

 Summary

  •  Pointers store addresses
  • * → value, & → address
  •  Essential for performance & system-level coding
  •  Backbone of DSA, OS, Embedded, Interviews

You may also like...