Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Constant: Difference between revisions

From Coderwiki
create Constant
 
add 'declaring and initializing' section
 
Line 6: Line 6:


For these compile-time constants, they can't use any [[Function|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]].
For these compile-time constants, they can't use any [[Function|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 ==
Declaring a constant is usually the same as [[variable declaration]], but using an extra/different [[keyword]], usually <code>const</code>.
Similarly, initializing a constant is usually the same as [[variable initialization]], but using an extra/different [[keyword]], usually <code>const</code>.

Latest revision as of 13:37, 9 August 2025

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.