Python Pointers & Value vs Pointer Semantics
Go features safe pointers without pointer arithmetic. Master address-of (&), dereferencing (*), heap vs stack escape analysis, and how to choose between value copies and pointer mutation.
"Passing by value is like photocopying a document and handing over the copy. Passing a pointer is giving someone the GPS coordinates to the original file cabinet."
Deep Dive: How It Works
Address-of & Dereference: &x gets the pointer address; *p accesses the underlying value.
No Pointer Arithmetic: Go pointers cannot be arbitrarily offset like C pointers, ensuring memory safety.
Escape Analysis: The Go compiler automatically moves local variables to the heap if their pointers escape the function scope.
Syntax Blueprint
var x int = 42 p := &x *p = 100 // x is now 100
Use & to capture the address of a variable; use * to dereference and mutate the underlying value.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Dereferencing a nil pointer (*nilPointer).Why it happens: An uninitialized pointer holds nil (address 0x0).
How to fix: Always verify if ptr != nil before dereferencing if the pointer can be optional.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Implement In-Place Pointer Swap
Write a function swap(a, b *int) that swaps the values of the two integer pointers in place.
In main(), initialize x := 10 and y := 20.
Call swap(&x, &y) and print "x: %d, y: %d".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.