There are three types of logical operators: AND (&&), OR(||) and NOT(!)

Out of these AND and OR are binary, whereas NOT is a unary operator.

AND (&&):

OR (||):

NOT (!):

In the above illustrations we saw truth table of AND, OR and NOT logical operators. Now we will take an example and try to understand how these operators will work.

- main()

{

int i = 10, j = 20 , k ;

k = i && j;

printf(“i = %d j = %d k = %d\n”,i,j,k);

}

In the above example, value of i is 10, that means non – zero value for j is 20 which is also a non – zero value. Hence, as both the values are non – zero, therefore answer of k will be 1.

Now I’ll proceed to another example :

2. main()

{

int i = 10, j = 20 , k ;

k = i || ( j = 50);

printf(“i = %d j = %d k = %d\n”,i,j,k);

}

Answer : i =10 , j =20 , k =1

### Like this:

Like Loading...

*Related*

## Leave a Reply