ccompiler.inOnline C Compiler & Docs
Language Reference2026-08-144 min read

Complete C operators reference guide: arithmetic, relational, logical, bitwise, and assignment operators with precedence rules and code.

Overview of C Operators

An operator in C is a symbol that instructs the compiler to perform specific mathematical, logical, or relational manipulations on operands.

C provides a rich set of built-in operators categorized by function and precedence level.


1. Arithmetic Operators

Arithmetic operators perform basic mathematical calculations on numerical operands:

OperatorMeaningExampleResult (if a = 10, b = 3)
+Additiona + b13
-Subtractiona - b7
*Multiplicationa * b30
/Division (Truncated for integers)a / b3
%Modulo (Remainder after division)a % b1
++Increment (Pre / Post)++a / a++11
--Decrement (Pre / Post)--a / a--9
c (ISO Standard)
#include <stdio.h>

int main() {
    int x = 20;
    int y = 6;

    printf("Addition: %d\n", x + y);
    printf("Integer Division: %d\n", x / y);
    printf("Remainder Modulo: %d\n", x % y);

    return 0;
}

2. Relational & Equality Operators

Relational operators compare two values and evaluate to 1 (true) or 0 (false):

OperatorDescriptionExample
==Equal toa == b
!=Not equal toa != b
>Greater thana > b
<Less thana < b
>=Greater than or equal toa >= b
<=Less than or equal toa <= b

3. Logical Operators

Logical operators combine boolean expressions:

OperatorDescriptionBehavior
&&Logical ANDReturns 1 if both operands are non-zero (short-circuits on false).
||Logical ORReturns 1 if at least one operand is non-zero (short-circuits on true).
!Logical NOTInverts the truth value of the operand.

4. Bitwise Operators

Bitwise operators manipulate integer data at the individual bit level:

OperatorMeaningDescription
&Bitwise ANDBit is 1 if both corresponding bits are 1.
|Bitwise ORBit is 1 if either corresponding bit is 1.
^Bitwise XORBit is 1 if bits differ (exclusive OR).
~Bitwise NOTFlips all bits (one's complement).
<<Left ShiftShifts bits left, multiplying by powers of 2.
>>Right ShiftShifts bits right, dividing by powers of 2.
c (ISO Standard)
#include <stdio.h>

int main() {
    unsigned char a = 0b00001100; /* 12 */
    unsigned char b = 0b00011001; /* 25 */

    printf("a & b = %d\n", a & b);   /* 8 */
    printf("a | b = %d\n", a | b);   /* 29 */
    printf("a << 1 = %d\n", a << 1); /* 24 */

    return 0;
}

5. Operator Precedence & Associativity Table

When an expression contains multiple operators, precedence determines evaluation order (higher numbers bind first):

Precedence LevelOperatorsAssociativity
1 (Highest)(), [], ->, ., ++ (postfix), -- (postfix)Left-to-Right
2+ (unary), - (unary), !, ~, * (deref), & (addr), sizeof, ++ (prefix), -- (prefix)Right-to-Left
3* (multiply), /, %Left-to-Right
4+ (add), - (subtract)Left-to-Right
5<<, >>Left-to-Right
6<, <=, >, >=Left-to-Right
7==, !=Left-to-Right
8& (bitwise AND)Left-to-Right
9^ (bitwise XOR)Left-to-Right
10| (bitwise OR)Left-to-Right
11&& (logical AND)Left-to-Right
12|| (logical OR)Left-to-Right
13?: (ternary conditional)Right-to-Left
14=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=Right-to-Left
15 (Lowest), (comma)Left-to-Right

Related Reference Guides & Tutorials