📜  逻辑不对!带有示例的C中的运算符

📅  最后修改于: 2021-05-25 21:54:37             🧑  作者: Mango

是逻辑运算符的一种,读为“ NOT ”或“ Logical NOT ”。该运算符用于执行“逻辑非”操作,即类似于数字电子设备中的反相器门的函数。

句法:

!Condition

// returns true if the conditions is false
// else returns false

下面是一个例子来演示!运算符:

例子:

// C program to demonstrate working
// of logical NOT '!' operators
  
#include 
  
int main()
{
  
    // Taking a variable a
    // and set it to 0 (false)
    int a = 0;
  
    // logical NOT example
  
    // Since 0 is considered to be false
    // !a will yield true
    if (!a)
        printf("Condition yielded True\n");
    else
        printf("Condition yielded False\n");
  
    // set a to non-zero value (true)
    a = 1;
  
    // Since a non-zero value is considered to be true
    // !a will yield false
    if (!a)
        printf("Condition yielded True\n");
    else
        printf("Condition yielded False\n");
  
    return 0;
}
输出:
Condition yielded True
Condition yielded False
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。