Basics of Programming serves as a syntax lookup for core constructs across different languages. While syntax changes, the underlying concepts map to the same CPU Instructions.
1. Variables & Mutability
Variables are named storage locations in memory.
Statically Typed (C, Rust): The type is known at compile time, determining the exact memory size on the Stack(s).
Dynamically Typed (Python): Variables are references to objects on the Heap(s), resolved at runtime.
C
Mutable by default. You must specify the type explicitly.
int x = 5; // 4 bytes on Stackx = 6; // OKconst int y = 10; // Immutable (Read-Only)
Rust
Immutable by default. Focuses on safety.
let x = 5;// x = 6; // Compile Error!let mut y = 5;y = 6; // OK
Python
Dynamic. Variables are just name tags for objects.
x = 5x = "Hello" # x now points to a String object
2. Conditionals (Branching)
Control flow allows the program to make decisions. At the hardware level, these compile down to Jump or Branch instructions based on flags set by the ALU.
C
Truthy: Any non-zero value is true. if (1) works.
Parentheses () required.
if (x > 5) { printf("Big");} else if (x == 5) { printf("Equal");} else { printf("Small");}
Rust
Strict Booleans:if (1) is an error. Must be true/false.
Expression:if returns a value, allowing functional patterns.
let result = if x > 5 { "Big" } else { "Small" };
Python
Indentation defines blocks.
if x > 5: print("Big")elif x == 5: print("Equal")else: print("Small")
3. Loops (Iteration)
Repeating code blocks. Loops are the primary driver of Time Complexity. Correctness is often proven via Loop Invariants.
C
The classic for loop gives you total control over the index.
// Init; Condition; Updatefor (int i = 0; i < 10; i++) { printf("%d", i);}
Rust
Prefers Iterators for safety (avoids out-of-bounds errors).
// Exclusive range (0 to 9)for i in 0..10 { println!("{}", i);}// Loop forever (cleaner than while(true))loop { break; }
Python
Also Iterator-based.
for i in range(10): print(i)
4. Functions
Reusable blocks of code. Calling a function creates a new Stack Frame in memory to hold arguments and local variables.
C
Return type precedes the name.
int add(int a, int b) { return a + b;}
Rust
Uses fn. The last line (without semicolon) is an implicit return.
fn add(a: i32, b: i32) -> i32 { a + b // Expression return}
Python
Uses def.
def add(a, b): return a + b
5. Arrays & Collections
Storing multiple values.
C
Raw Arrays. Fixed size, contiguous memory. No bounds checking (Dangerous).
int arr[5] = {1, 2, 3, 4, 5};int val = arr[10]; // Segfault or Garbage (Undefined Behavior)
Rust
Arrays (Fixed) vs Vectors (Dynamic). Strict bounds checking.
let arr = [1, 2, 3]; // Fixed size Stack arraylet vec = vec![1, 2, 3]; // Dynamic Heap vector// let val = arr[10]; // Panic! (Crash safely)
Python
Lists. Dynamic, heterogeneous (can hold mix of types).
lst = [1, "two", 3.0]lst.append(4)
6. Error Handling
How the language deals with failure.
C
Return Codes. Functions return 0 (Success) or -1 (Error).