c / beginner
Snippet
Defining Constants with const
The 'const' keyword qualifies a variable as read-only. Once initialized, the value of a constant cannot be changed during the program's execution, which helps prevent accidental modifications.
snippet.c
1
2
const float PI = 3.14159;const int MAX_USERS = 100;
Breakdown
1
const float PI = 3.14159;
Creates a floating-point constant that cannot be reassigned later.
2
const int MAX_USERS = 100;
Defines an integer constant, often used for configuration limits.