Logical Operators in C, all in one example 2

C Programming Language / Operators and Enums in C Language

1080

Program:

// C Program to demonstrate the working of logical operators

#include"stdio.h"
int main()
{
    int a = 5, b = 5, c = 10, result;

    result = (a = b) && (c > b);
    printf("(a = b) && (c > b) equals to %d \n", result);

    result = (a = b) && (c < b);
    printf("(a = b) && (c < b) equals to %d \n", result);

    result = (a = b) || (c < b);
    printf("(a = b) || (c < b) equals to %d \n", result);

    result = (a != b) || (c < b);
    printf("(a != b) || (c < b) equals to %d \n", result);

    result = !(a != b);
    printf("!(a == b) equals to %d \n", result);

    result = !(a == b);
    printf("!(a == b) equals to %d \n", result);

    return 0;
}

Output:

(a = b) && (c > b) equals to 1
(a = b) && (c < b) equals to 0
(a = b) || (c < b) equals to 1
(a != b) || (c < b) equals to 0
!(a == b) equals to 1
!(a == b) equals to 0
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.