C++ 的 逻辑与
等级 299 次按键
用&&组合两个条件(年满18岁且有驾照),两者都为true,所以输出“Can drive”。
C++ 代码
// 将年龄25存入age1int age = 25;// bool只能保存true或false,这里表示有驾照2bool hasLicense = true;// &&(逻辑与)只有两边都为true时才为true// 25 >= 18和hasLicense都为true,因此执行代码块3if (age >= 18 && hasLicense) { // 输出“Can drive”4 cout << "Can drive" << endl;5}运行结果
Can drive
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C++ 代码中需要输入的符号及其出现次数。
<× 4;× 3=× 3"× 2&× 2(× 1)× 1{× 1}× 1>× 1