Home / Programs / Logical Operators in C, all in one example 2
Programming Example

Logical Operators in C, all in one example 2

👁 1,116 Views
💻 Practical Program
📘 Step by Step Learning
Study this program carefully to understand the logic, output, and explanation in a structured way.

Program Code

// 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 . . .

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.