---
title: 3.9 Equality Operators
description: "Equality operators compare two values to determine whether they are equal or different. The `==` operator tests for equality, while the `!=` operator tests for inequality. ``` #include int main() { int a = 10; int b = 20; printf(\"a…"
url: "https://edcret.in/docs/c-programming/operators-and-expressions/3-9-equality-operators/"
updated: "2026-09-07"
category: C Programming / Operators and Expressions
---

# 3.9 Equality Operators

Equality operators compare two values to determine whether they are equal or different. The `==` operator tests for equality, while the `!=` operator tests for inequality.

```
#include <stdio.h>

int main()
{
    int a = 10;
    int b = 20;

    printf("a == b : %d\n", a == b);
    printf("a != b : %d\n", a != b);

    return 0;
}
```

### Example Output

```
a == b : 0
a != b : 1
```

### Explanation

The equality operators are:

| Operator | Meaning |
| --- | --- |
| `==` | Equal to |
| `!=` | Not equal to |

The expression:

```
a == b
```

checks whether `a` and `b` have equal values. Since `10` and `20` are different, the expression produces `0`.

The expression:

```
a != b
```

checks whether the values are different. Since they are different, it produces `1`.

The assignment operator `=` is different from the equality operator `==`. `=` assigns a value, while `==` compares values.
