C Control StatementsC FunctionsC ArrayC PointerC Dynamic MemoryC StringC MathC StructureC UnionC File HandlingC PreprocessorC Command LineC Misc |
Logical operators in cWhen an Expression that combines two or more expressions is know as logical expression. To combining these expressions we use logical operators.This logical operator return 0 for false and 1 for true. The operands may be constant,expressions or variables . In c language there are three logical operator –
Here in this example NOT is a unary operator while the others two OR, AND are binary operators. Before using These operators let us understand the concept of these operators of true and false. in c language any non zero value regarded as true and the zero is regarded as false. AND (&&) operatorThis operators gives the net result true if both condition will be true, Otherwise result will be false. Let us see Example
Let us understand the concept of AND operator. Let us take three variables a=15, b=6,c=0 let us take expression and results
in the last row example the expression a&&c we have take only variables a and c. since non zero value is regarded as true and zero value is regarded as false, so in this example variable a considered as true and variable c is considered as false. OR (||) OperatorThis OR operator gives the result false. if both conditions have the value false. otherwise the result is true
Let us understand the concept of OR operator. so take three variables a=20, b=15, c=0;
NOT (!) OperatorThis is a Unary operator and its negates the values of any condition. So if the value of the condition is false then it gives the result true. And the value of condition is true then it gives the result false. So now understand the concept of NOT operator.
Let us understand the concept of NOT operator
|