Programming in CProgress: 0/1 completed
Subjects/Programming in C

Pointers & Address Logic

Easy
10 mins read
Prerequisites
  • Variables and Data Types
  • Memory Addresses overview

Introduction

Pointers C language ka sabse powerful aur logical element hai. Kuch log pointers se darte hain, par pointers aur kuch nahi bas ek special variables hote hain jo normal values (like 10, 'A') store karne ke bajaye dusre variables ka address (like 0x7ffd...) store karte hain. simple, address book ki tarah!

Real-Life Analogy

💡 House Map and Address book

Storing address of another home to access details

Concept TermReal-life Analogy Mapping
Variable ValueThe physical furniture inside a house
Memory LocationThe physical house plot numbers (e.g. House No. 201)
Pointer VariableA slip of paper writing 'House No 201' written on it
Dereferencing (*ptr)Going to the address written on the slip and checking or updating the furniture inside

Detailed Concept Explanation

C standard declaration of pointers uses asterisk (*): `int *ptr;` -> Yeh compiler ko batata hai ki `ptr` ek pointer variable hai jo integer variables ka memory address rakhega. `ptr = &x;` -> Address of operator (&) pointer me memory allocation register map karta hai. `*ptr` -> Dereference operator. Isse hum variables ki space context change ya update kar sakte hain parameters override karke.

Visual Diagram

Pointer Variable (ptr)
0x7ffd98b
Value is another Address
Address: 0x7ffd100
Points to
Normal Variable (x)
45
Actual integer value
Address: 0x7ffd98b
Important Point
  • Pointer size system hardware architecture par depend karta hai (32-bit par 4 bytes, 64-bit par 8 bytes) variable types (char, int, float) par nahi.
  • Pointer arithmetic integer offsets apply karta hai based on data type size offset increment logic.
  • Null pointer points to 0x0 or safe address, accessing it causes Segmentation Fault.
Mnemonic / Memory Trick

A-V-A-P (Address Value Address Pointer)

& is Address, * is Value at Address, pointer holds the address

Mnemonic to remember the core pointer indicators.
Avoid This Common Mistake
Students dereference syntax direct call double assign call mix up double pointer mapping memory address allocation. E.g. declaring `int *ptr` and direct assign values `*ptr = 20` without initial allocation initialization (causing stack overflow / segment errors).
GATE Exam Insights
GATE loves pointer pointer chains, multi-dimensional array operations, and function call parameters by reference. Operator precedence of postfix, prefix and dereferencing operations is highly tricky.

Practice Mini Quiz

Revision Summary (One-Page Notes)

  • Pointers store addresses of other variables.
  • Declared using *.
  • Address retrieved using &.
  • Dereferenced using *.
  • Size is platform dependent.