Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 13:37, 9 August 2025 by Dylan (talk | contribs) (add 'declaring and initializing' section)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Constants in programming are variables in which their value does not change during the runtime of the program.

Compile-time constants

edit edit source

Some programming languages evaluate constants at compile time. This means that their value is worked out by the compiler and is then hardcoded into the binary.

For these compile-time constants, they can't use any functions or data that is only available at runtime. For example, compile-time constants can't take in user input or call any other non-constant function.

Declaring and initializing constants

edit edit source

Declaring a constant is usually the same as variable declaration, but using an extra/different keyword, usually const.

Similarly, initializing a constant is usually the same as variable initialization, but using an extra/different keyword, usually const.