Topic 21 of 100 Operators in C Interactive Tutorial

C Operators Guide: Complete Operator Categories With Examples

12 mins read Last updated: 22 Aug 2026 21,500 views
C Compiler 0.00%

What is C Operators Guide? Core Concept & Direct Summary

Core Objective & Problem Statement

What are the major categories of operators in C and how are they classified by operands and functionality?

Direct Answer Summary

If variables are the nouns of C — the things your program talks about — thenoperators are the verbs. They're the symbols thatdothings: add numbers, compare values, flip bits, make decisions possible.

Here's what makes C's operator set special: it's remarkably rich for such a small language. Beyond the arithmetic everyone expects, C gives you bit-level operators that most modern languages hide, increment shortcuts that became so iconic they named a language after them (C++ — get it?), and a ternary operator that compresses entire if-else statements into one line.

This guide is yourcomplete mapof C's operator landscape — every category, what it does, and a working example of each. Consider it the hub: each category below links to its own deep-dive guide when you're ready to go further.

How Does C Operators Guide Work? In-Depth Mechanics & Architecture

What Is an Operator in C?

Anoperatoris a symbol that tells the compiler to perform a specific operation on values (calledoperands):

main.c
Run Online
int total = 10 + 5;
//          ↑   ↑   ↑
//      operand operator operand

Based on how many operands they need, operators come in three shapes:

  • Unary— one operand:-x,!flag,count++
  • Binary— two operands:a + b,x < y,p && q
  • Ternary— three operands: the one-of-a-kind?:

And based onwhat they do, they fall intosix major categories. Let's tour each one.

Category 1: Arithmetic Operators — The Calculators

The math toolkit you already know, plus one special guest:

OperatorNameExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiplication10 * 330
/Division10 / 33⚠️
%Modulus (remainder)10 % 31
main.c
Run Online
#include <stdio.h>
int main() {
    int a = 10, b = 3;
    printf("%d\n", a / b);
    // 3 — integer division drops the fraction!
    printf("%d\n", a % b);
    // 1 — the remainder survives
    return 0;
}

Two things every beginner must know:integer division truncates(10 / 3is3, not3.33), and themodulus%— which returns the remainder — is secretly one of the most useful operators in programming. Even or odd?n % 2. Last digit?n % 10. Wrap-around logic?%again.

Category 2: Relational Operators — The Comparers

These compare two values and answer with C's boolean logic:1 (true) or 0 (false):

OperatorMeaningExampleResult
==Equal to5 == 51
!=Not equal to5 != 31
>Greater than5 > 31
<Less than5 < 30
>=Greater or equal5 >= 51
<=Less or equal4 <= 51
main.c
Run Online
int marks = 72;
printf("%d\n", marks >= 40);
// 1 — true, printed as a number

⚠️The eternal trap:=assigns,==compares.if (x = 5)setsx to 5 and is always true.if (x == 5)actually checks. One character, endless debugging sessions.

Category 3: Logical Operators — The Combiners

When one condition isn't enough, logical operators combine them:

OperatorNameTrue When...
&&ANDbothsides are true
||ORat least oneside is true
!NOTthe value is false (flips truth)
main.c
Run Online
int age = 20;
int hasID = 1;
if (age >= 18 && hasID) {
    printf("Entry allowed\n");
    // both true — runs
}
if (age < 13 || age > 60) {
    printf("Discount ticket\n");
    // either true — would run
}
if (!(age >= 18)) {
    printf("Minor\n");
    // NOT flips the result
}

The pro detail — short-circuit evaluation:C stops early when the answer is decided. InA && B, ifAis false,Bnever runs (the result is already false). InA || B, ifAis true,Bnever runs. This isn't just speed — programmers deliberately place safety checks first:if (ptr != NULL && ptr->value > 0)worksbecausethe second half never executes when the pointer is null.

Category 4: Bitwise Operators — The Bit Surgeons

C's specialty — operators that manipulateindividual bitsof data. This is where C touches the metal:

OperatorNameWhat It Does
&Bitwise ANDBit is 1 only ifbothbits are 1
|Bitwise ORBit is 1 ifeitherbit is 1
^Bitwise XORBit is 1 if bits aredifferent
~ComplementFlips every bit
<<Left shiftShifts bits left (×2 per position)
>>Right shiftShifts bits right (÷2 per position)
main.c
Run Online
int a = 5;
// binary: 0101
int b = 3;
// binary: 0011
printf("%d\n", a & b);
// 1  (0001 — only last bit matches)
printf("%d\n", a | b);
// 7  (0111)
printf("%d\n", a ^ b);
// 6  (0110 — different bits)
printf("%d\n", a << 1);
// 10 (1010 — doubled!)

That last one is a gem:left-shifting by 1 doubles a number, and right-shifting halves it. Bitwise operators are the backbone of embedded systems, device drivers, and anywhere hardware registers need poking.

⚠️ Don't confuse&(bitwise AND) with&&(logical AND) —5 & 3is1, but5 && 3is also1... while4 & 2is0but4 && 2is1. Different operators, different worlds.

Category 5: Assignment Operators — The Updaters

Beyond plain=, C offerscompound assignmentsthat combine operation and assignment:

OperatorExampleEquivalent To
=x = 10assign
+=x += 5x = x + 5
-=x -= 5x = x - 5
*=x *= 5x = x * 5
/=x /= 5x = x / 5
%=x %= 5x = x % 5
&=,|=,^=,<<=,>>=x <<= 2bitwise + assign
main.c
Run Online
int score = 100;
score += 50;
// 150
score *= 2;
// 300
score %= 7;
// 6

Shorter to write, and once fluent, faster to read. Real C code uses these constantly.

Category 6: Unary Operators — The Solo Acts

Operators that work on asingle operand— including the two most famous symbols in C:

Increment and Decrement (++ and --)

main.c
Run Online
int i = 5;
i++;
// 6 — add one
i--;
// 5 — subtract one

But there's a twist —pre vs postposition:

main.c
Run Online
int a = 5, b;
b = a++;
// b = 5, THEN a becomes 6  (post: use first, change after)
b = ++a;
// a becomes 7 FIRST, b = 7 (pre: change first, then use)

This tiny difference powers a thousand interview questions.

The Other Unary Stars

main.c
Run Online
int x = -10;
int positive = -x;
// unary minus: 10
int size = sizeof(int);
// sizeof: 4 (bytes)
int flag = !0;
// logical NOT: 1
int *ptr = &x;
// address-of: where x lives
int value = *ptr;
// dereference: the value there

That last pair —&(address-of) and*(dereference) — are the gateway to pointers, C's most powerful feature.

The Special One: The Ternary Operator (?:)

C's only three-operand operator compresses an entire if-else into one expression:

main.c
Run Online
// the long way
if (marks >= 40) {
    result = 'P';
} else {
    result = 'F';
}
// the ternary way — one line
char result =(marks >= 40) ? 'P' : 'F';
//           condition      ? if-true : if-false

Perfect for small decisions:max = (a > b) ? a : b;. Resist nesting them, though — stacked ternaries become unreadable riddles.

When Operators Collide: A Word on Precedence

What does2 + 3 * 4give? Not 20 — multiplication strikes first, giving14. Every operator has aprecedencerank, and when operators compete, higher rank wins:

main.c
Run Online
int r1 = 2 + 3 * 4;
// 14 — * beats +
int r2 =(2 + 3) * 4;
// 20 — parentheses override everything
int r3 = 10 > 5 && 3 < 8;
// 1  — comparisons beat &&, && beats nothing here

The professional habit:when in doubt, parenthesize.(a + b) * cis never wrong, never ambiguous, and never needs a precedence table to read.

The Complete Quick-Reference Table

CategoryOperatorsOne-Line Memory Hook
Arithmetic+ - * / %%= remainder,/on ints truncates
Relational== != < > <= >=Answer is always 1 or 0
Logical&& || !Short-circuits when decided
Bitwise& | ^ ~ << >>Works on individual bits
Assignment= += -= *= /= %=Compound = operate + store
Unary++ -- ! ~ sizeof & * -One operand only
Ternary?:if-else in one line

Runnable C Code Example & Practical Implementation

main.c
Run Online
#include <stdio.h>
int main() {
    int a = 15, b = 4;
    printf("Sum: %d | Remainder: %d | Is Greater: %d\
", a + b, a % b, a > b);
    return 0;
}

Key Takeaways, Best Practices & Memory Safety Rules

Best Practice & Key Takeaways
Use parentheses ( ) liberally in compound expressions to make evaluation order unambiguous and eliminate subtle precedence bugs.

Frequently Asked Questions & Technical Interview Insights

Technical Interview & Viva Questions

Frequently asked C programming interview questions
Q

Q: Which operator in C is ternary?

A: The conditional operator `?:` (e.g. `condition ? val_if_true : val_if_false`).
Q

Q: What does the comma operator `,` do?

A: Evaluates its left operand, discards the result, then evaluates its right operand and returns the right operand's value.

Related Tools, Tutorials & Authoritative References

Recommended Interactive Tools

Authoritative Standards & Citations