0
0
Cprogramming~5 mins

Why operators are needed in C

Choose your learning style9 modes available
Introduction

Operators help us do math and make decisions in programs easily. They let us add, compare, and change values quickly.

When you want to add two numbers like prices or scores.
When you need to check if one value is bigger than another.
When you want to combine conditions, like checking if a user is logged in and has permission.
When you want to change a value, like increasing a counter by one.
When you want to find the remainder after dividing numbers.
Syntax
C
result = operand1 operator operand2;

Operands are the values or variables you work with.

Operators tell the computer what to do with those values.

Examples
Adds 5 and 3, stores 8 in sum.
C
int sum = 5 + 3;
Checks if 7 is greater than 4, stores 1 (true) in isBigger.
C
int isBigger = (7 > 4);
Finds remainder of 10 divided by 3, stores 1 in remainder.
C
int remainder = 10 % 3;
Sample Program

This program shows how operators do math with two numbers and print the results.

C
#include <stdio.h>

int main() {
    int a = 10;
    int b = 3;
    int sum = a + b;
    int diff = a - b;
    int product = a * b;
    int quotient = a / b;
    int remainder = a % b;

    printf("Sum: %d\n", sum);
    printf("Difference: %d\n", diff);
    printf("Product: %d\n", product);
    printf("Quotient: %d\n", quotient);
    printf("Remainder: %d\n", remainder);

    return 0;
}
OutputSuccess
Important Notes

Operators make code shorter and easier to read than writing long instructions.

Using the wrong operator can cause bugs, so choose carefully.

Summary

Operators let you do math and comparisons in code.

They work with values to produce new results.

Using operators correctly helps your program make decisions and calculations.