Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Wednesday, July 8, 2020

Logical operator in C

Logical operator in C
By Ahmad Irshad | C Programming Tutorial > Logical operaotr in C

Relational operators are used to compare between two operands. However, relational operators does not support comparison of three or more quantities.

For example, suppose you need to check range of a number. You need to check whether a number n is in between 1-100 or not. For that you must check two conditions, first check if n > 1 finally check if n < 100.

Logical operators are used to connect two or more expressions as a singal expressioin. It returns boolean value either true (1) or false (0) depending on the given expression.

There are three logical operators in C.

OperatorsDescription
&&Logical AND
||Logical OR
!Logical NOT
Logical AND (&&) operator:

We use logical AND operator in situations when two or more conditions must be true for a decision.

Logical AND (&&) operator is a binary operator. It returns true (0) when both the conditions are satisfied. Otherwise it returns false (1). 
 
For Exmaple:

  1. #include <stdio.h>
  2. int main() { int x = 6, y = 3;
  3. if (x < 10 && y > 2)   printf("True, since both the conditions are satisfied.");
  4. else
  5. printf("False, since both the conditions are not satisfied.");
  6. return 0;
  7. }

Logical OR || operator:

Logical OR || operator is a binary operator. It returns true (1) even if one (or both) of the conditions is satisfied. Otherwise it returns false (0). 

For Example:

  1. #include <stdio.h>
  2. int main() { int x = 6, y = 3;
  3. if (x > 10 || y > 2)   printf("It returns true, since 2nd condition is satisfied.");
  4. else
  5. printf("It returns false, if both conditions are not satisfied.");
  6. return 0;
  7. }

Logical NOT ! operator:

Logical NOT !  is a unary operator it has only one operand. It is used to reverse the logical state of its operand. In other words, if a condition is true, then logical NOT operator will make it false. 

For Example:

  1. #include <stdio.h>
  2. int main() { int x = 6, y = 3;
  3. if (!(x == y))   printf("It returns true, since x!=y condition is satisfied.");
  4. else
  5. printf("It returns false, if both conditions are not satisfied.");
  6. return 0;
  7. }

Logical NOT Operator In C | Protec






Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us