zoukankan      html  css  js  c++  java
  • 11 逻辑运算符

    1,用于连接多个条件(一般来讲就是关系表达式),最终的结果要么是真(非0表示),要么是假(0表示)

    2,逻辑运算符一览

      假设变量A的值为1,变量B的值为0,则:

      

     1 #include<stdio.h>
     2 void main() {
     3     int a = 10, b = 99;
     4     if (a < 2 && ++b>99) {
     5         printf("ok100");
     6     }
     7     printf("b=%d", b);
     8 
     9     //打印结果:b=99
    10     //1,在进行 && 操作时,如果第一个条件为false,则后面的条件不再判断
    11     //2,该现象称为短路现象,所以逻辑与也称为短路逻辑与
    12 }
    1  1 #include<stdio.h>
    2  2 void main() {
    3  3     int a = 10, b = 99;
    4  4     if (a > 2 && ++b>99) {
    5  5         printf("ok100");
    6  6     }
    7  7     printf("b=%d", b);
          //打印结果:0k100 b=100
          //++b , 先自增 b=100,再比较,100>99成立
    1  1 #include<stdio.h>
    2  2 void main() {
    3  3     int a = 10, b = 99;
    4  4     if (a > 2 && b++>99) {
    5  5         printf("ok100");
    6  6     }
    7  7     printf("b=%d", b);
          //打印结果:  b=100
          //b++, 先比较 99>99不成立,再自增 b=100
  • 相关阅读:
    leetcode Lowest Common Ancestor of a Binary Tree
    leetcode 141、Linked list cycle
    leetcode 136、Single Number
    tensorflow使用
    c++ priority_queue
    python语法
    CSS基础之选择器
    并发编程的一些理解
    封装的绑定与多态
    继承与派生
  • 原文地址:https://www.cnblogs.com/shanlu0000/p/12339970.html
Copyright © 2011-2022 走看看