

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


1. What is a Pointer? A pointer is a variable that stores the memory address of another variable, rather than storing a direct value (like an integer or character). Think of a normal variable as a house, and a pointer as the mail carrier
2. Core Operators You Must Know To master pointers, you only need to understand two critical symbols: The Ampersand (&) | "Address-of" Operator: This retrieves the exact memory address (location) where a variable is sitting. The Asterisk () | "Dereferencing" Operator:* When placed in
Memory Visualization Imagine your computer's RAM looks like this grid: Variable Name Memory Address Value Stored num 0x7ffee3 45 ptr 0x7ffee
3. Pointer Syntax Breakdown (Cheat Sheet) #include int main() {
int age = 20; int *p = &age; printf("Value of age: %d\n", age); // Outputs: 20 printf("Address of age: %p\n", &age); // Outputs something like: 0x7ffee // Dereferencing printf("Value stored at p: %d\n", *p); // Outputs: 20 // Changing the value via the pointer *p = 21; printf("New value of age: %d\n", age); // Outputs: 21 return 0; }
4. Dynamic Memory Allocation (DMA) By default, C allocates memory automatically (Static Allocation). However, if you don't know how much memory you'll need until the program runs, you must use Dynamic Memory Allocation from the library. The Big 3 DMA Functions 1. malloc() (Memory Allocation): Allocates a specific block of memory in bytes. It leaves the memory full of "garbage values" (old leftover data).