Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Data Types

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Data type က variable ထဲမှာ ဘယ်လို data သိမ်းမလဲဆိုတာ သတ်မှတ်ပေးပါတယ်။ မှန်ကန်တဲ့ data type ရွေးတာက memory အသုံးပြုမှု၊ calculation accuracy နဲ့ code ဖတ်ရလွယ်မှုအတွက် အရေးကြီးပါတယ်။

cpp
#include <iostream>
#include <string>
using namespace std;

int main() {
    int students = 35;
    double averageMark = 82.75;
    char section = 'B';
    bool passed = true;
    string course = "C++ Foundation";

    cout << course << endl;
    cout << "Students: " << students << endl;
    cout << "Average: " << averageMark << endl;
    cout << "Section: " << section << endl;
    cout << "Passed: " << passed;
    return 0;
}

int က ကိန်းပြည့်၊ double က decimal number, char က စာလုံးတစ်လုံး၊ bool က true/false, string က စာသားအတွက် သုံးပါတယ်။ Student count လို decimal မလိုတဲ့ data ကို int သုံးတာ ပိုသင့်တော်ပါတယ်။

You should see
C++ Foundation Students: 35 Average: 82.75 Section: B Passed: 1

Info

Money, grade average, measurement လို decimal တန်ဖိုးတွေမှာ double ကို float ထက် ပိုအသုံးများပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • int price = 19.99; လိုရေးရင် decimal part ပျောက်နိုင်ပါတယ်။ Data type မကိုက်ရင် result မမှန်နိုင်တာကို သတိထားပါ။
Data Types | Thuta Learning