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

Booleans

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

C အစောပိုင်း style မှာ boolean ကို 0 နဲ့ non-zero value အဖြစ်အသုံးပြုပါတယ်။ <stdbool.h> ထည့်ရင် bool, true, false ကို ပိုဖတ်ရလွယ်အောင်သုံးနိုင်ပါတယ်။

c
#include <stdio.h>
#include <stdbool.h>

int main() {
  bool isLoggedIn = true;
  bool hasPermission = false;

  printf("Logged in: %d
", isLoggedIn);
  printf("Permission: %d", hasPermission);
  return 0;
}

true က output ထုတ်ရင် 1false က 0 ဖြစ်ပါတယ်။ Condition တွေမှာ ဒီ value တွေကို အများကြီးသုံးပါတယ်။

You should see
Logged in: 1 Permission: 0

Info

Boolean variable name ကို is, has, can နဲ့စရေးတာက code ဖတ်ရလွယ်စေပါတယ်။ ဥပမာ isPaid, hasAccess

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

  • stdbool.h မထည့်ဘဲ bool သုံးရင် compiler error ဖြစ်နိုင်ပါတယ်။
Booleans | Thuta Learning