Variables and constants
Variables are named memory locations with modifiable values, while constants are named memory locations with fixed values. Both improve code readability and maintainability by replacing magic numbers with meaningful identifiers. Variables support dynamic algorithms, while constants represent fixed values like mathematical constants or configuration settings. Choosing between variables and constants depends on whether values change during program execution.
Real World
In a game like Minecraft, the player's health is a variable that changes when taking damage, while the maximum stack size of 64 is a constant that never changes during gameplay.
Exam Focus
Explain WHY constants improve maintainability — changing one declaration updates every usage, reducing errors across the codebase.
How well did you know this?