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

  1.    
  2. #include < stdio.h >  
  3.   
  4. int main()  
  5. {  
  6.     int a = 20, b = 30, c;  
  7.   
  8.     if( !(a > b) )  
  9.         b = 50;  
  10.     c = 70;  
  11.   
  12.     printf("b = %d and c = %d\n", b, c);  
  13.   
  14.     return 0;  
  15. }  

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