Variable ဆိုတာ program ထဲမှာ value သိမ်းထားတဲ့ box လေးလို တွေးနိုင်ပါတယ်။ C++ က statically typed language ဖြစ်လို့ variable တစ်ခုမသုံးခင် data type ကို ကြေညာပေးရပါတယ်။ ဥပမာ int age ဆိုရင် age ထဲမှာ integer value သာ သိမ်းမယ်လို့ compiler ကို ကြိုပြောထားတာပါ။
cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
int age = 20;
double height = 5.8;
char grade = 'A';
string name = "Thuta";
bool isLearning = true;
cout << name << " is " << age << " years old." << endl;
cout << "Height: " << height << endl;
cout << "Grade: " << grade << endl;
cout << "Learning C++: " << isLearning;
return 0;
}ဒီ example မှာ data type မတူတဲ့ variable ၅ မျိုးကို သိမ်းထားပါတယ်။ string သုံးထားလို့ #include <string> ထည့်ထားတာပါ။ cout မှာ << ကို သုံးပြီး စာသားနဲ့ variable value တွေကို ဆက်ထုတ်နိုင်ပါတယ်။
You should see
Thuta is 20 years old. Height: 5.8 Grade: A Learning C++: 1Info
bool ကို cout နဲ့ထုတ်ရင် default အနေနဲ့ 1 သို့မဟုတ် 0 ထွက်နိုင်ပါတယ်။ true က 1, false က 0 ဖြစ်ပါတယ်။