iOS Development Learning Record the 8th day of C language learning-----logical operators

Source: Internet
Author: User

I. Introduction to logical operators

1. Logical operator:&& (with) | | (OR)! (non)

The formula:&& is true, a false is False

|| The truth is true, a false is False

! False is True, True is False

2, we use the following example to see the specific details:

#include <stdio.h>int main (int argc, const char * argv[]) {    //define two int type variable    int num1=2,num2=3;        if (num1>0 && num2>0) {        printf ("Num1 and num2&& results are true \ n");//Here is a description of num1,num2 is greater than 0    }    if ( Num1>0 && num2<0) {        printf ("Num1 is true, Num2 is false, num1&&num2, the final result is false \ n");//Not printed    }    if ( num1>0 | | num2<0) {        printf ("Num1 is true, Num2 is false, num1| | NUM2, the final result is true \ n ");//This will be printed out    }            if (num1>0) {        printf (" Here is true \ n ");//This will be printed    }    // We can now print out the value of!num1    printf ("%d\n",!num1),//!num1 with a value of 0        if (!num1>0) {        printf ("Here is false \ n");//This will not print  because num1>0   but the value of!NUM1 is 0    0>0 false    }    if (!num1==0) {        printf ("Here is true \ n");//This will be printed    }                return 0;}

iOS Development Learning Record the 8th day of C language learning-----logical operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.