Pointers vs References Comparison
🟡 Intermediate
📖 Definition
A reference (T&) is an immovable alias bound at initialization that cannot be null. A pointer (T*) is an independent variable that can be null, reassigned, or incremented.
💡 Code Example
#include <iostream>
int main() {
int a = 10;
int& ref = a; // Alias
int* ptr = &a; // Memory address
ref = 20; // Modifies 'a' directly
std::cout << "a: " << a << ", *ptr: " << *ptr << "\n";
return 0;
}