ブール型

ブール型は true または false の論理値の格納に意図されています。それぞれの数値表現は 1 と 0 です。

例:

bool a = true;
bool b = false;
bool c = 1;

内部表現は 1 バイトサイズの整数です。論理式では、他の整数または実数型や式を使用することが出来ることに留意すべきです。コンパイラはエラーを生成しません。この場合、ゼロ値は false として解釈され、他の全ての値は true とされます。

例:

  int i=5;
  double d=-2.5;
  if(i) Print("i = ",i," and is set to true");
  else Print("i = ",i," and is set to false");
 
  if(d) Print("d = ",d," and has the true value");
  else Print("d = ",d," and has the false value");
 
  i=0;
  if(i) Print("i = ",i," and has the true value");
  else Print("i = ",i," and has the false value");
 
  d=0.0;
  if(d) Print("d = ",d," and has the true value");
  else Print("d = ",d," and has the false value");
 
//--- 実行結果
//   i= 5 and has the true value
//   d= -2.5 and has the true value
//   i= 0 and has the false value
//   d= 0 and has the false value

参照

ブール演算子優先順位のルール