Program run နေစဉ်အတွင်း တန်ဖိုးမပြောင်းစေချင်တဲ့ data တွေကို const နဲ့ရေးပါတယ်။ ဥပမာ PI, tax rate, maximum score, minutes per hour စတာတွေပါ။
c
#include <stdio.h>
int main() {
const int MINUTES_PER_HOUR = 60;
const double PI = 3.14159;
printf("Minutes: %d
", MINUTES_PER_HOUR);
printf("PI: %.2lf", PI);
return 0;
}const ထည့်လိုက်ရင် အဲဒီ variable ကို နောက်ထပ် value အသစ်ပြန်သတ်မှတ်လို့မရတော့ပါ။ ပြောင်းမိရင် compiler က error ပြပါမယ်။
You should see
Minutes: 60 PI: 3.14Info
Constant name တွေကို uppercase နဲ့ရေးတာက project တွေမှာ ဖတ်ရလွယ်တဲ့ naming style တစ်ခုပါ။