How Does Relational Operators | C Programming Tutorial Work?

Relational operators in C programming are like comparators that help decide if one thing is bigger, smaller, or equal to another, just like when you compare your toys with a friend’s.

Imagine you and your best friend each have a bag of marbles. You want to know who has more marbles. That’s what relational operators do: they compare values, and based on that comparison, they tell the program whether something is true or false.

Like a Marble Game

Let's say you have 5 marbles and your friend has 3. If you use the greater than operator (>), it checks if your number of marbles is bigger than your friend’s. Since 5 > 3, it says true, which means you win!

If both of you had 4 marbles each, then using the equal to operator (==) would say true, because you're both equally matched.

These operators are used in conditions, like if you want your program to do something only when a certain condition is met. So, relational operators help programs make smart decisions, just like how you decide who gets extra candy based on whose marble count is higher!

Take the quiz →

Examples

  1. Comparing if 5 is greater than 3 using >
  2. Checking if two numbers are equal with ==
  3. Deciding which number is bigger between 10 and 7

Ask a question

See also

Discussion

Recent activity