面试题答案
一键面试fn main() {
let a = true;
let b = false;
if a &&!b {
println!("specific condition met");
}
}
在这段代码中,&&
是逻辑与操作符,它用于连接两个布尔表达式,只有当左右两边的表达式都为true
时,整个表达式才为true
。!
是逻辑非操作符,它将b
的布尔值取反,即false
变为true
。所以当a
为true
且b
为false
时(经过取反后!b
为true
),a &&!b
这个表达式为true
,从而执行println!
语句打印出specific condition met
。