CHAPTER 06 / 26
C Constants
Learn how to create values that should not change during program execution.
01 — Syntax
const data_type NAME = value;
02 — Example
#include <stdio.h>
int main() {
const int DAYS = 7;
printf("Days = %d", DAYS);
return 0;
}03 — Important Points
- Constants should be used for values that should not change.
- Use uppercase names for constants by convention.
04 — Common Mistakes
- Trying to change a const variable.
- Forgetting to initialize the constant.
05 — Real-World Use
Constants are useful for configuration values, limits and fixed application settings.
06 — Practice
Create a small program that demonstrates the main idea of C Constants.