C Operators

Logical operators

#include 
#include 
main() 
{ 
	int i,j;    // comma operator used
	printf ("value of i");
	scanf ("%d",&i);
	printf ("value of j");
	scanf ("%d",&j);
	if(i>0)&&(j>0)    //logical condition
		printf("i & j are positive");
	else
		printf("end of program");
} 

C has the following logical operators, they compare or evaluate logical and relational expressions.
	Operator	Meaning
	&& 		Logical AND
	||		Logical OR 
	!		Logical NOT 
Logical AND (&&)
This operator is used to evaluate 2 conditions or expressions with relational operators simultaneously. If both the expressions to the left and to the right of the logical operator is true then the whole compound expr....

Logical OR (||)
The logical OR is used to combine 2 expressions or the condition evaluates to true if any one of the 2 expressions is true.
Example 
		a < m || a < n 
The expression evaluates to true if any one of them is true or if both of them are true. It evaluates to true if a is less than either m or n and when a is less than both m and n.

Logical NOT (!)
The logical not operator takes single expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it just reverses the value of the expression.
Example: 
               ! (x >= y) 
The NOT expression evaluates to true only if the value of x is neither greater than or equal to y ...

Make Comments..!!


Oops!! No posts from user.

Download Android App