Pointer Fundamentals, Memory Addressing & Address Arithmetic
Unit 3: Arrays, Pointers & String Manipulation • Problem Solving Using C
👨🏫 Professor's Mental Model: The Physical House vs Street Address Note
Variable tumhara ghar hai jisme data (jaise 42) rehta hai. Pointer ek paper slip hai jisme us ghar ka address (jaise 0x1000) likha hai! Address-of operator (&) ghar ka address pata karta hai, aur Dereference operator (*) us address par jakar ghar ka darwaza kholta hai aur andar ka saman nikalta hai! Pointer arithmetic sadak par chalne jaisa hai: agar int pointer ko +1 karoge toh wo 1 byte nahi balki pure 4 bytes aage koodega!
Academic Lecture Notes & Solved Study Pages
Unit 3 • Core Concepts, Step-by-Step Proofs & Notebook Solutions
1. Computer Memory Architecture & Pointer Declaration
1. Address-of Operator (`&`): Returns the physical memory location of a variable.
2. Dereferencing / Indirection Operator (`*`): Directly accesses or mutates the value stored at the target address pointed to by the pointer.
2. The 4 Special Pointer Types
3. Pointer Arithmetic Rules & Scaling
Pointer arithmetic is strictly governed by the data type size (`sizeof(*ptr)`):
Example: If `int *p = 1000`, then `p++` results in address `1004` (not 1001!).
RAM Pointer Architecture: int num = 42; int *ptr = #
0x1000 is passed to functions in Call by Reference.Interactive Tested Code Example
#include <stdio.h>
int main(void) {
int num = 42;
int *ptr = #
printf("=== POINTER MEMORY DEREFERENCE DEMO ===\n");
printf("Value of 'num': %d\n", num);
printf("Address of 'num' (&num): %p\n", (void *)&num);
printf("Value in pointer 'ptr': %p\n", (void *)ptr);
printf("Address of pointer (&ptr): %p\n", (void *)&ptr);
printf("Dereferenced value (*ptr): %d\n\n", *ptr);
// Mutating variable through pointer indirection
*ptr = 99;
printf("After *ptr = 99 -> num value is now: %d\n\n", num);
// Pointer Arithmetic Scaling Demo
int arr[3] = {10, 20, 30};
int *p_arr = arr;
printf("Base Address (p_arr): %p\n", (void *)p_arr);
printf("p_arr + 1 (Advances 4 bytes): %p\n", (void *)(p_arr + 1));
return 0;
}🎯 University Exam Scoring Blueprint
- Always draw the memory box diagram with addresses (e.g. 0x1000 and 0x2000) when explaining pointers in exams.
- Explicitly state that adding two pointers together (p1 + p2) is a compilation syntax error.
- Emphasize that void * is a generic pointer requiring explicit typecasting before dereferencing.