---
title: "Relational and assignment operators"
subject: "Computer Programming"
chapter: 3
key: "semester_1/computer_programming:relational-assignment-operators"
source: https://www.bctengineer.com/q/semester_1/computer_programming/relational-assignment-operators
site: BCT Engineering
---

# Relational and assignment operators

Computer Programming · Chapter 3: Introduction to ‘C’ programming

- Asked in: 2070 Asar, 3 marks
- Video: [9_ Assignment and Relational Operators in C](https://www.youtube.com/watch?v=tt4pm2FypVk) — WiooPikings Pvt Ltd
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/relational-assignment-operators
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-3

## Question

What are relational operators and assignment operators? Explain with examples.

## Short answer

Relational operators compare values (e.g., a>b returns 1 or 0). Assignment operators include = and compound forms: +=, -=, *=, /=, %=, which combine operation and assignment. For example, x += 5 is equivalent to x = x + 5.

## Answer

**Relational operators** (`<`, `<=`, `>`, `>=`, `==`, `!=`) compare two operands and give 1 if the relation is true, otherwise 0. They are used in conditions of `if` and loops, for example `a > b`.

**Assignment operators** store a value in a variable. The basic one is `=`; the compound ones (`+=`, `-=`, `*=`, `/=`, `%=`) combine an operation with assignment: `x += 5` means `x = x + 5`.

Example:
```c
#include <stdio.h>
int main(void)
{
    int x = 10;
    x += 5;  printf("x += 5  -> %d\n", x);
    x -= 3;  printf("x -= 3  -> %d\n", x);
    x *= 2;  printf("x *= 2  -> %d\n", x);
    x /= 4;  printf("x /= 4  -> %d\n", x);
    x %= 4;  printf("x %%= 4  -> %d\n", x);
    printf("x == 2 gives %d, x > 5 gives %d\n", x == 2, x > 5);
    return 0;
}
```

Output:
```text
x += 5  -> 15
x -= 3  -> 12
x *= 2  -> 24
x /= 4  -> 6
x %= 4  -> 2
x == 2 gives 1, x > 5 gives 0
```

Note that `=` assigns while `==` compares.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Where are relational operators mainly used?
   A. In conditions of if and loops
   B. To store values in variables
   C. To allocate memory
   D. To declare arrays
   Answer: A. They produce 1 or 0 and are used in conditions. (Key point: Relational use)

2. x += 5 means:
   A. x = 5
   B. x = x + 5
   C. x = x == 5
   D. x = 5 + 5
   Answer: B. Compound assignment combines the operation with assignment. (Key point: Compound assignment)

3. What is the difference between = and ==?
   A. = compares and == assigns
   B. Both compare
   C. = assigns while == compares
   D. Both assign
   Answer: C. = stores a value; == tests equality. (Key point: Assign vs compare)

## Related in Computer Programming

- [Relational and logical operators](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Arelational-logical-operators) — Computer Programming, chapter 3

## Related in other subjects

- [Relational operators comparing lengths](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aoverload-relational-length) — Object Oriented Programming, chapter 5
- [Distance class relational operators](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adistance-relational-overload) — Object Oriented Programming, chapter 5
- [Complex numbers relational operators](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Acomplex-relational-overload) — Object Oriented Programming, chapter 5
