π―
STUDENT NOTES Β· C & C++ WEEK 4 OF 8
Pointers: Remote Controls for Memory π―
The chapter with the scary reputation β explained with house numbers and TV remotes. You've got this.
1Every variable has a house number
βοΈ
Chip: Every variable LIVES somewhere in memory β at an address, like a house number. The & operator asks: "where do you live?"
2A pointer stores an address
A pointer is a variable whose value is⦠another variable's address. And * means "go to that address and look inside":
π€
Bittu: p holds x's address. Writing *p = 9 changes x itself β a remote control for x. THIS is the line where pointers click.
The Pointer Remote πΊ β press buttons on p, watch x change!
x = 5 (p points at x's address)
3Why scanf needed that &
π¦
Professor Hoot: Week 1 mystery solved: scanf("%d", &age) passes age's ADDRESS so scanf can deliver the answer to the right house. It was pointers all along!
4Bugly's deadliest trap
π
Bugly: A pointer that points NOWHERE in particularβ¦ then you write through it. My masterpiece β the crash that built my reputation:
5struct β build your own type
βοΈ
Chip: A struct bundles different types into ONE record β like a player card. With a pointer to a struct, use the arrow: p->goals.
6Quick quiz! π§
int x = 5; int *p = &x; *p = 9; β what is x now?
π‘ p points at x, so writing through *p changes x itself. Remote control engaged.
&x gives youβ¦
π‘ & = "address of". The house number where x lives.
7Your mission π
Mission 1: Print a variable's value AND its address (%p) β see where it lives.
Mission 2: Change a variable through a pointer, like the toy above β in real C.
Mission 3: Build a struct Student with name and marks. Fill it, print it.
Week 4 complete β pointers CLICKED! π―
Next: malloc, free, files β and the memory leaks that eat RAM.
Go to Week 5: Memory & Files β