【发布时间】:2021-04-16 14:30:43
【问题描述】:
语言:C
如果输入 0,则布尔表达式输出 0,否则输出 1。
按照上面的说法,
案例 1:
输入
#include <stdio.h>
#include <stdbool.h>
main()
{
int a = 1,
b = 2;
bool res = ((a == b) && ("your "));
printf("res = %d", res);
}
输出
res = 0
案例 2:
输入
bool res = (!(a == b) && ("your "));
printf("res = %d", res);
输出
res = 1
案例 3: 现在我将prinf函数添加到(“你的”)
输入
bool res = ((a == b) && printf("your "));
printf("res = %d", res);
输出
res = 0 //adding printf doesn't change the output
案例 4: 输入
bool res = (!(a == b) && printf("your "));
printf("res = %d", res);
输出
your res = 1 // i expected just "res = 1" not "your res = 1"
CASE 3中没有执行打印功能却在CASE 4中执行的打印功能怎么办?
【问题讨论】:
标签: c boolean printf logical-and