C Programming Interview / Viva Q&A: 4 (Logical NOT Operator)

In this video tutorial lets put our understanding of logical NOT(!) operator to test.

Related Read:
Logical Operators In C
Relational Operators In C

Logical NOT(!) Operator in C Program

 
#include < stdio.h >

int main()
{
    int a = 20, b = 30, c;

    if( !(a > b) )
        b = 50;
    c = 70;

    printf("b = %d and c = %d\n", b, c);

    return 0;
}

In this c source code, a is 20 and b is 30. Inside if condition we check if a is greater than b. But a is less than b, so it returns false(0). But we’ve a Logical NOT operator(!) surrounding the false result. So it converts it to true. Hence the next line of code that is, b = 50 gets executed.

So the output is: b = 50 and c = 70

C Programming Interview / Viva Q&A: 4 (Logical NOT Operator)


[youtube https://www.youtube.com/watch?v=gRl9-zZMqm8]

YouTube Link: https://www.youtube.com/watch?v=gRl9-zZMqm8 [Watch the Video In Full Screen.]


For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert