作用:用于根据表达式的值返回真值或假值
逻辑非
示例
int a = 10;
//在C++中 除了0都为真
cout << !a << end1; // 0
cout << !!a << end1; // 1
system("pause");
return 0;
逻辑与
//同样都是真的,为真,其余都为假
int a = 10;
int b = 10;
cout << a&&b << end1; // 1
a = 0 ;
b = 10 ;
cout << a&&b << end1; // 0
a = 0 ;
b = 0 ;
cout << a&&b << end1; // 0
system("pause");
return 0;
逻辑或
//同样都是假的,为假,其余都为真
int a = 10;
int b = 10;
cout << (a || b) << end1; // 1
a = 0 ;
b = 10 ;
cout << (a || b) << end1; // 1
a = 0 ;
b = 0 ;
cout << (a || b) << end1; // 0
system("pause");
return 0;
页面更新:2024-04-19
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号