A boolean data type is declared with the bool
keyword and can only take the values true
or false
.
When the value is returned, true
= 1
and false
= 0
.
bool isCodingFun = true;
bool isFishTasty = false;
cout << isCodingFun; // Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false)
Try it Yourself »
Boolean values are mostly used for conditional testing, which you will learn more about in a later chapter.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!