Programming Fundamentals
Programming Fundamentals tests whether you can read and write precise code: variables, data types, expressions, selection, iteration, functions, parameter passing, scope, and error handling. The exam favors tracing short programs and explaining why an output occurs, not memorizing syntax.
Core constructs
A variable names a storage location; its type determines allowed operations and representation. Assignment changes state; equality comparison tests it. Integer division truncates toward zero in many languages, while real division keeps a fraction. Boolean operators short-circuit: in A AND B, if A is false, B may not be evaluated. Loops need initialization, a condition, and an update that guarantees termination.
Functions and scope
Parameters pass values into a function. Pass-by-value copies the argument; pass-by-reference exposes the original variable to mutation. Local variables exist only during a call; global variables are visible across scopes but make programs harder to reason about. Recursion needs a base case and a recursive case that moves toward it.
Worked example
Consider: total ← 0; for i from 1 to 4: total ← total + i*i. Trace: i=1 total=1; i=2 total=5; i=3 total=14; i=4 total=30. Output 30. The loop runs four times; the final update uses i=4 before the loop exits.
Traps
Off-by-one errors are common: “from 1 to 4” includes 4. Do not confuse = assignment with == equality. In integer division, 7/2 is 3, not 3.5. A function that prints is not the same as one that returns a value. Check whether a recursive call changes its argument; otherwise it may not terminate.