This is the fourth day of my participation in the August Text Challenge.More challenges in August

directory

  • Logical operators
    • 1. And operation &&
    • 2. Or operation | |
    • 3. Non-arithmetic!
  • Two. Guess you like it

C/C++ learning Directory >> C language basics

Logical operators

In C language if/else condition judgment, the condition judgment of an if statement can be composed of multiple expressions, for example: what is a student with excellent grades? Excellent students = high grades + hard work, both are indispensable;

1. With the operation&&

And operations require the use of key characters&&Is used to join two or more expressions into one. All expressions must betrue, the whole expression istrue, or forfalse;

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / @ Author: apes said programming / / @ Blog (personal Blog address) : www.codersrc.com // @file :C language logic operator // @time :2021/05/28 08:00 // @motto: A thousand miles without a step, a small stream without a river or sea, the wonderful program life needs to be accumulated unrelentingly! /************************************************************************/ #include "stdafx.h" #include <stdio.h> int Main () {// whether score good bool bHeightScore = true; Bool bHardStudt = false; If (bHeightScore && bHardStudt) printf(" Get good grades and work hard, be a good student \n"); // If bHeightScore and bHardStudt are both true, else printf(" Not a good student \n") can be executed; Printf (" End of main! \n"); return 0; } /* End of main function for students with high grades! Press any key to continue.. */Copy the code

2. Or operation||

Or operations require the use of key characters||Is to join two or more expressions into one. Any expression istrue, the whole expression is zerotrue; Only if all expressions arefalseWhen the whole expression is zerofalse

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / @ Author: apes said programming / / @ Blog (personal Blog address) : www.codersrc.com // @file :C language logic operator // @time :2021/05/28 08:00 // @motto: A thousand miles without a step, a small stream without a river or sea, the wonderful program life needs to be accumulated unrelentingly! /************************************************************************/ #include "stdafx.h" #include <stdio.h> int main() { bool bHeightScore = true; bool bHardStudt = false; If (bHeightScore | | bHardStudt) printf (" study hard or score is high, is necessarily learn weak students with excellent grades are one of god \ n "); // If either bHeightScore or bHardStudt is true else printf(" I am a poor student \n"); Printf (" End of main! \n"); return 0; } /* Output result: either study hard or score high, is bound to be one of the students of weak learning god excellent performance! Press any key to continue.. */Copy the code

3. The operation!

Non-operations require the use of key characters!Is used to reverse the result of a single expression,

  • If the result of the original expression isfalse, prefixes the expression with an operator!It’s going to be the inversetrue

  • If the original calculation istrue, prefixes the expression with an operator!It’s going to be the inversefalse

    /*/ / @author: // @blog: www.codersrc.com // @file :C language logic operator // @time :2021/05/28 08:00 // @motto: A thousand miles without a step, a small stream without a river or sea, the wonderful program life needs to be accumulated unrelentingly! / * /

    # include “stdafx. H” # include < stdio, h >

    int main()

    {

    bool bHeightScore = true;

    bool bHardStudt = false;

    if (! BHeightScore) printf(" I got bad grades \n"); // Only bHeightScore equals false can be executed. Else printf(" I got good grades \n"); if (! BHardStudt) {// Only bHeightScore equals false can be executed, not an operation! Printf (" I don't want to try, rich woman? Thirty less years of struggle. } printf(" I study hard \n"); Printf (" End of main! \n"); return 0;Copy the code

    }

    /* Output result:

    I got good grades and I don’t want to try. Are there any rich women? Thirty years less struggle that main function ends! Press any key to continue.. */

C language logic operators are essential in development, are relatively simple;

twoGuess you like

  1. Install Visual Studio
  2. Install the Visual Studio plug-in, Visual Assist
  3. Visual Studio 2008 uninstall
  4. Visual Studio 2003/2015 Uninstall
  5. Set the Visual Studio font/background/line number
  6. C Hello World
  7. C code comments
  8. C data type/variable type
  9. C language variable declaration and definition
  10. C format controller/placeholder
  11. C printf function
  12. C conditional judgment if/else
  13. C language logic operator

C language logic operator

This article is published by the blog – Ape Say Programming Ape Say programming!