c++ bool类型函数

c++ bool类型函数

bool型函数指的是返回值为bool类型的函数,其调用方式和int 型函数没有太大的区别。

bool型变量的值只有 真 (true) 和假 (false)。bool可用于定义函数类型为布尔型,函数里可以有 return true; return false 之类的语句。

示例:

#include

using namespace std;

bool cmp(int a,int b){

if(a > b){

return true;

}else{

return false;

}

}

int main()

{

int a = 5;

int b = 6;

if(cmp(a,b)){

cout << "a> b!" << endl;

}else{

cout << "a< b!" << endl;

}

return 0;

}

相关推荐