Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

Boolean Literals ใน C++ คืออะไร?

Boolean literals คือ literals ที่มีความหมายเป็น true หรือ false เท่านั้น ใน C++ มี boolean literals เพียงสองตัวคือ true และ false literals นี้เป็นชนิด bool สามารถใช้ได้ดังนี้:

ตัวอย่าง

#include <iostream>
using namespace std;
int main() {
    bool my_bool = true;
    if(my_bool) {
        cout << "My bool is true!" << endl;
    }
    return 0;
}

ผลลัพธ์

โค้ดนี้จะให้ผลลัพธ์:

My bool is true!