Variable ဆိုတာ data သိမ်းတဲ့ box လေးတစ်ခုလိုပါ။ C မှာ variable တစ်ခုမသုံးခင် data type ကိုကြေညာရပါတယ်။ ဘာကြောင့်လဲဆိုတော့ compiler က memory ဘယ်လောက်ယူရမလဲ၊ value ကို ဘယ်လိုဖတ်ရမလဲ သိဖို့လိုလို့ပါ။
c
#include <stdio.h>
int main() {
int age = 20;
float price = 19.99;
char grade = 'A';
printf("Age: %d
", age);
printf("Price: %.2f
", price);
printf("Grade: %c", grade);
return 0;
}int က integer, float က decimal number, char က character တစ်လုံး သိမ်းပါတယ်။ %d, %.2f, %c တွေက format specifier တွေဖြစ်ပြီး variable ကို ဘယ်ပုံစံနဲ့ output ထုတ်မလဲ ပြောတာပါ။
You should see
Age: 20 Price: 19.99 Grade: AInfo
%.2f ဆိုတာ decimal ၂ လုံးပဲပြမယ်ဆိုတဲ့အဓိပ္ပါယ်ပါ။ Money, price တွေပြတဲ့အခါ အသုံးဝင်ပါတယ်။