Logical Operators

Logical Operators are used for performing logical operations , such as joining(Or,And) conditions ,negations(Not).

Following table shows all the logical operators supported by C language.
OperatorsWhat They Do ..Precedence
!It gives the complement of all values. In C , all values are Positive(Boolean 1) except 0.1
&& Performs the AND operation on operands.2
||Performs the OR operation.3




C Example


#include<stdio.h>

int main() {

	int a=10,b=20,c=30,d,e,g,h,f;

	d=!a;

	e=((a>b)&&(a<c));

	//  One condition false

	f=((a<b)&&(a<c));

	//  Both conditions  true

	g=((a>b)||(a<c));

	//  One condition true

	h=((a>b)||(c< a));

	//  Both conditions false

	printf("a=%d , b=%d",a,b);

	printf("\n\nd=%d , e=%d",d,e);

	return 0;

}



Advertisement
Need to catch up your pending software project work? Access your online private workspace having your essential programming tools with virtual PC from www.CloudDesktopOnline.com with 24*7*365 days reliable tech-support from Apps4Rent.