我需要知道如何根据以下代码计算 if 语句的输出 true 或 false:
#include <stdio.h>
enum designFlags {
BOLD = 8,
ITALICS = 9,
UNDERLINE = 4
};
int main() {
int myDesign = BOLD & ITALICS;
printf("%d", myDesign);
if(BOLD & ITALICS)
printf("Design is ITALIC");
else
printf("Design is not ITALIC");
return 0;
}
最佳答案
首先浏览一下针对运算符的 C 书籍。
如果(粗体和斜体)
'&' 它是按位与运算符。即它对位进行操作
BOLD = 8 = 0000 1000
&
ITALICS = 9 = 0000 1001 (check the truth table of bitwise & )
-------------------------
= 0000 1000 =8
因此,if(8) 表示 true,因此会打印“Design is Italics”。
关于c - If 语句使用 | 输出运算符(operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47239930/