C Relational Operators

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Relational Operators?

Relational operators compare two values and yield 1 (true) or 0 (false) as an int. They drive if, while, and for conditions.

Remember
a == b    a != b
a <  b    a >  b
a <= b    a >= b
/* result is int: 1 or 0 */

Cheat Sheet

Keep these facts handy while you work with Relational Operators in C.

TopicDetail
Equal== (never a single =)
Not equal!=
Result typeint 1 or 0
StringsCompare with strcmp, not ==

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Logical Operators.

Example 1 — Printing comparison results

Each comparison evaluates to 0 or 1.

C
#include <stdio.h>

int main(void) {
    int x = 7, y = 10;

    printf("x == y: %d\n", x == y);
    printf("x != y: %d\n", x != y);
    printf("x <  y: %d\n", x < y);
    printf("x >= y: %d\n", x >= y);
    return 0;
}

How It Works

  1. x == y is false, so it prints 0.
  2. x != y and x < y are true.
  3. The results are plain integers, so they can be added or stored.

Edge Cases & Pitfalls

Check these before relying on Relational Operators in real programs.

float

Exact float equality

Rounding means 0.1 + 0.2 == 0.3 is false. Compare with fabs(a - b) < epsilon.

chain

Chained comparisons

1 < x < 10 is (1 < x) < 10, always true. Write 1 < x && x < 10.

Key Takeaways

  • Result: 1 or 0.
  • Equality: ==, not =.
  • Range: combine with &&.

One line: Relational operators compare two values and yield 1 (true) or 0 (false) as an int.

Frequently Asked Questions

An int: 1 if the relation holds and 0 if not. C has no separate boolean result from these operators (stdbool.h adds a bool type that converts to 0/1).
No. == compares pointers. Use strcmp(a, b) == 0 to compare string contents.
Continue with "C Logical Operators" next. Combine conditions with && (and), || (or), and ! (not). The C Operators hub lists every topic in order.

Next: Logical Operators

Combine conditions with && (and), || (or), and ! (not).

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful