Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Basics of C Programming
  5. Expressions
  6. Relational operators

Relational operators

Relational operators are used to compare two operands.

  • The result of evaluation of a relational expression is a boolean constant i.e. 0 or 1
  • The result of the relation expression is 1 if the specified condition is true else it is 0
  • An expression that includes relation operator is termed as condition

There are six relational operators,

Example

Illustration of Relational operator

#include<stdio.h>
int main()
{
	int a;
	a = 2 < 3 != 2;
	printf("a=%d",a);
	return 0;
}

Output

a=1

Explanation

All the relational operators are having left to right associativity. Thus 2<3 is evaluated first and it returns 1 as it is true. Then 1 != 2 is done which is true, so the result is 1

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments