Operators in C Programming: The Engine Behind Every Decision Your Code Makes

Operators in C Programming

Most beginners think programming is about storing data. It’s not. A program becomes powerful only when it acts on that data — performs calculations, compares values, and makes decisions. That transformation happens because of one core concept: Operators. In this guide, you’ll learn not just what operators are, but how they actually drive program behavior at a system level.

  • What operators do inside a program
  • What are C operators?
  • How do they control logic and decision-making?
  • Why mistakes in operators break real systems
  • How to think like a programmer while using them

So far, we have learned about:

  • Different data types
  • Variables
  • How values are stored in memory

However, an important question arises: What is the use of storing data if we cannot operate on it? Storing data is only the first step. A program becomes more powerful when it can use that data to perform meaningful operations. In real-world programs, we perform operations such as:

  • Mathematical computations (addition, subtraction, multiplication, division)
  • Relational comparisons
  • Logical decisions
  • Conditional evaluations
  • Bitwise operations (used in low-level programming)

All these operations are performed on variables and values — this is where operators in C come into play. Understanding operators from a system perspective. Think of a program as a system:

  • Data types -> define the type of data exists.
  • Variables -> store that data.
  • Operators -> decide what happens to that data.

Without operators, a program would simply store information with no behaviour and is just a memory storage. With operators, it becomes a dynamic system capable of processing and decision-making. Operators act as instructions that tell the program how to manipulate and evaluate data. In simple terms, they help a program:

  • Calculate results
  • Compare values
  • Make decisions
  • Update its state

How operators work internally (Beginner insight)

When a C program is executed:

  • The compiler interprets the operator.
  • Converts them into machine-level instructions.
  • The CPU executes those instructions.

This means every operator directly affects how the program runs at the hardware level. This is one of the reasons C is so powerful — it gives you fine control over system behaviour.

#include <stdio.h>

int main() {
  int a = 10, b = 5;
  
  printf("Addition : %d\n", a + b);
  printf("Comparison (a > b) : %d\n", a > b);
  
  return 0;
}
Output:

Addition: 15
Comparison: 1

Here: “+ performs addition and > compares values“. This is how operators make programs work.

Classification based on the number of operands

Operators can also be classified based on how many values (operands) they work on.

Unary operator

Unary operators work on a single operand. Examples include:

  • Increment (++)
  • Decrement (- -)

These are commonly used to:

  • Update counters
  • Control loops
  • Adjust values step-by-step

Binary operator

Binary operators work on two operands. Examples include:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)

These form the core of:

  • Calculations
  • Comparisons
  • Logical operations

Ternary operator

The ternary operator works on three operands. The conditional operator (?:) is an example of a ternary operator. It is used for:

  • Decision-making in a compact form
  • Replacing simple if-else conditions

Types of operators in C with examples

Operators in C are divided into multiple categories based on their purpose.

Arithmetic operators in C (computation Engine)

Used for performing mathematical operations. These operators power everything from basic math to complex algorithms. We are all familiar with these arithmetic operators. In addition, there is one more operator, which is the modulus operator (%), used to compute the remainder of a division operation. It includes:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)

Arithmetic operators are fundamental for:

  • Calculations
  • Algorithm development
  • Data transformation
  • Performance-critical systems

Every numerical logic in programming depends on them. They are the backbone of any computation.

#include <stdio.h>

int main() {
  int first = 12, second = 8;
  
  printf("Addition: %d\n", first + second);           // Addition of two variables, it will perform addition (12 + 8)
  printf("Subtraction: %d\n", first - second);        // Subtraction of two variables, it will subtract second from first (12 - 8)
  printf("Multiplication: %d\n", first * second);     // perform the multiplication of first and second variable (12 * 8)
  printf("Division: %d\n", first / second);           // Division Operator (12 / 8)
  printf("Modulus: %d\n", first % second);            // Modulus operator returns the remainder (12 % 8)

  return 0;
}
Output:

Addition: 20
Subtraction: 4
Multiplication: 96
Division: 1
Modulus: 4

Relational operators in C (comparison system)

These operators are used to compare values. It includes:

  • Equal to (==)
  • Not equal to (!=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

They help answer questions like:

  • Is one value greater than another?
  • Are two values equal?
  • Is the condition true or false?

These operators always produce: true (1) or false (0). They are critical for decision-making, conditional execution and control flow.

#include <stdio.h>

int main() {
  int first = 5, second = 10;
  
  printf("Is first equal to second? %d\n", first == second);                   // return: 0 (false)
  printf("first and second are not equal %d\n", first ! = second);             // return: 1 (true)
  printf("is first greater than second? %d\n", first > second);                // return: 0 (false), and first < second return: 1
  printf("is first less than or equal to second? %d\n", first < = second);     // return 1

  return 0;
}
Output:

Is first equal to second? 0
first and second are not equal 1
is first greater than second? 0
is first less than or equal to second? 1

Logical operators in C (decision system)

Logical operators are used to combine multiple conditions. This operator includes:

  • AND ( && )
  • OR ( | | )
  • NOT ( ! )

They allow programs to evaluate complex scenarios like:

  • Condition A AND condition B must both be true.
  • Condition A OR condition B. At least one condition must be true.
  • NOT condition A, Use to one’s compliment.

They are essential for real-world logic such as complex decisions, validations and filtering logic. Without logical operators, programs cannot handle real-world conditions.

#include <stdio.h>

int main() {
  int number = 12;
  
  if(number > 10 && number < 20)
	  printf("The number %d is between 10 and 20\n", number);        // this will print only if both conditions are true.

  return 0;
}

Assignment operators in C (state management)

These operators are used to assign and update values. Assignment defines program state over time. It includes:

OperatorDescription
=Simple assignment operator, assign the value to variable
+=Add and assign. It performs the addition before assigning the value to the variable. This a += b is equivalent to, a = a+b
-=Subtract and assign. This operator performs the subtraction before assigning the value. This a -= b is equivalent to, a = a-b
*=Multiply and assign. It multiplies first, then assigns the result to the variable.
This a *= b is equivalent to, a = a*b
/=Division and assign. It performs the division, then assigns the value to the variable. This a /= b is equivalent to a = a/b
%=Modulus and assign. It takes a modulus and assigns the result to the variable.
This a %= b is equivalent to, a = a%b
<<=Left shift and assignment
>>=Right shift and assignment operator
&=Bitwise AND and assignment operator
^=Exclusive OR and assignment operator
|=Inclusive OR and assignment operator

They control:

  • How variables are initialized.
  • Values are modified over time.

Assignment is not just storing — it defines program state: every variable in your program represents a state, and assignment operators control how that state changes. Assignment operators simply code, reduce repetition and improve readability. Every program relies on assignment to maintain its state.

#include <stdio.h>

int main() {
  int first = 5, second = 10;
  
  printf("first = second %d\n", first = second);                               // assign 10 to the variable first
  
  // first += second is equivalent to first = first + second
  printf("first += second %d\n", first += second);
  
  // first -= second is equivalent to first = first - second
  printf("first -= second %d\n", first -= second);
  
  // first *= second is equivalent to first = first * second
  printf("first *= second %d\n", first *= second);
  
  // first /= second is equivalent to first = first / second
  printf("first /= second %d\n", first /= second);
  
  // first %= second is equivalent to first = first % second
  printf("first %= second %d\n", first %= second);
  
  // first &= second is equivalent to first = first & second
  printf("first &= second %d\n", first &= second);
  
  // first |= second is equivalent to first = first | second
  printf("first |= second %d\n", first |= second);
  
  // first ^= second is equivalent to first = first ^ second
  printf("first ^= second %d\n", first ^= second);
  
  // first << = second is equivalent to first = first << second
  printf("first << = second %d\n", first << = second);
  
  // first >> = second is equivalent to first = first >> second
  printf("first >> = second %d\n", first >> = second);

  return 0;
}
Output:

first = second 10
first += second 20
first -= second 10
first *= second 100
first /= second 10
first = second 0
first &= second 0
first |= second 10
first ^= second 0
first <<= second 0
first >>= second 0

Bitwise operators in C (advanced control)

Bitwise operators work directly on binary data (bits). They are mainly used in:

  • Embedded systems
  • Low-level programming
  • Hardware-level operations

This is one of the reasons C is powerful in system programming.

#include <stdio.h>

int main() {
    int first = 100, second = 10;

    printf("first & second: %d\n", first & second);
    printf("first | second: %d\n", first | second);
    printf("first ^ second: %d\n", first ^ second);
    printf("~first: %d\n", ~first);
    printf("first >> second: %d\n", first >> second);
    printf("first << second: %d\n", first << second);

    return 0;
}
Output:

first & second: 0
first | second: 110
first ^ second: 110
~first: -101
first >> second: 0
first << second: 102400

Increment and Decrement operators in C (control flow drivers)

These are special operators used for quick value updates. Used heavily in loops and counters.

  • ++ -> increases value by 1
  • – – -> decreases value by 1

They are heavily used in loops, counters, iterations, and performance-sensitive logic. These small operations drive large program behaviour.

#include <stdio.h>

int main() {
    int first = 11, second = 1;
    
    first--;
	  second++;

    printf("decrement first-- : %d\n", first);
    printf("increment second++ : %d\n", second);

    return 0;
}
Output:

decrement first-- : 10
increment second++ : 2

Misc Operators

There are a few more operators in the C language. These are sizeof(), &, * and ?: (ternary).

OperatorDescription
&Returns the address of a variable.
sizeof()It returns the size of a variable.
*This operator is use in pointers. Pointer to a variable.
? :This is a conditional operator, if the condition is true ? then the value E : otherwise value X
#include <stdio.h>

int main() {
    int first = 10;
    int *address_of_first = &first;

    printf("sizeof(first) = %d bytes\n", sizeof(first));
    printf("&first = %p\n", &first);
    printf("value stored at *address_of_first = %d\n", *address_of_first);
    printf("(45 < 40) ? 50 : 10 = %d\n", (45 < 40) ? 50 : 10);

    return 0;
}
Output:

sizeof(first) = 4 bytes
&first = 0061FF18
value stored at *address_of_first = 10
(45 < 40) ? 50 : 10 = 10

Operator precedence in C (execution order)

Not all operations are executed in the same order. C follows a strict hierarchy of execution. This determines which operation runs first and how expressions are evaluated. Ignoring this can lead to incorrect results and hidden bugs.

Associativity

This determines the execution direction (left to right or right to left). Incorrect understanding leads to wrong calculations and unexpected behaviour. This is one of the most overlooked concepts by beginners.

In short, both precedence and associativity are important. The table below has the priority from high to low, and associativity is left to right and right to left.

TypeOperatorAssociativity
Primary() , [ ] , ->Left to Right
Unary(type) , + , – , sizeof() , ~ , ! , * , & , ++ , – –Right to Left
Multiplicative* , / , %Left to Right
Additive+ , –Left to Right
Shift<< , >>Left to Right
Relational<<= , >>=Left to Right
Equality== , !=Left to Right
Bitwise AND&Left to Right
Bitwise XOR^Left to Right
Bitwise OR|Left to Right
Logical AND&&Left to Right
Logical OR||Left to Right
Conditional?:Right to Left
Assignment= , += , -= , *= , /= , %= , >>= , <<= , &= , |= , ^=Right to Left
Comma,Left to Right

Common mistakes that break programs

Understanding operators incorrectly can lead to serious bugs.

Confusing assignment and comparison

Using = instead of ==, this is one of the most common errors.

  • Assignment modifies values.
  • Comparison checks the value.

This mistake can completely break logic.

Misunderstanding operand types

Operations behave differently depending on data types. Example concept: integer operations and floating-point operations behave differently

Ignoring logical flow

Incorrect use of logical operators can: skip conditions, produce invalid results, execute wrong branches, and cause unexpected behaviour.

Ignoring operator precedence

Wrong assumptions about execution order can produce incorrect results. Without understanding precedence, expressions may not behave as expected and lead to incorrect evaluation of expressions.

Quick Summary

  1. Operators perform actions on data.
  2. Types include arithmetic, logical, relational etc.
  3. They control program logic and decision-making.
  4. Incorrect usage leads to major bugs.

How operators affect performance

In C, performance is directly linked to operations. Efficient use of operators can:

  • Reduce computation time
  • Optimize memory usage
  • Improve system performance

Operators are used in almost every real-world application. Every real system uses operators:

  • Banking systems -> calculations and validations.
  • Embedded systems -> hardware control.
  • Operating systems -> resource management.
  • Games -> physics, scoring, decision logic.

They are the backbone of program execution.

When using operators, don’t just write symbols. Think in terms of:

  • What operations are being performed?
  • What result is expected?
  • What data is involved?
  • What conditions must be true?

Think of operators as the “decision engine” of your program. Without them, your code is just stored data — not a working system. Operators are the decision-making and execution engine of a program.

  • Data types define what kind of data exists.
  • Variables define where that data is stored.
  • Operators define what happens to that data.

This is where programming shifts from static -> dynamic.

Now that you understand how operations work, your programs can finally process data and make decisions. But one key question remains: How does a program decide what to execute and when? This is where control statements in C come into play. In the next article, we will explore:

  • if and else conditions
  • loops (for, while)
  • decision-making logic

This is where your program starts behaving like an intelligent system.

Why operators matter in Embedded System

In embedded systems, operators are critical because they directly interact with hardware. For example:

  • Bitwise operators control registers.
  • Logical operators control system decisions.
  • Arithmetic operators manage sensor data.

Efficient use of operators leads to faster and more optimized systems.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top