When you don't want others (or yourself) to override existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only):
#include<stdio.h>
int main() {
const int myNum = 15;
myNum = 10;
printf("%d", myNum);
return 0;
}
You should always declare the variable as constant when you have values that are unlikely to change:
#include<stdio.h>
int main() {
const int minutesPerHour = 60;
const float PI = 3.14;
printf("%d\n", minutesPerHour);
printf("%f\n", PI);
return 0;
}
When you declare a constant variable, it must be assigned with a value:
Like this:
const int minutesPerHour = 60;
This however, will not work:
const int minutesPerHour;
minutesPerHour = 60; // error
#include<stdio.h>
int main() {
const int minutesPerHour;
minutesPerHour = 60;
printf("%d", minutesPerHour);
return 0;
}