Table of contents
1.
Introduction
2.
What are Operators in C?
3.
Types of Operators in C :
4.
1. Arithmetic Operators in C
4.1.
C
5.
2. Relational Operators in C
5.1.
C
6.
3. Bitwise Operators in C
6.1.
C
7.
4. Shift Operators in C
7.1.
C
8.
5. Ternary or Conditional Operators in C
8.1.
C
9.
6. Logical Operators in C
9.1.
C
10.
7. Assignment Operators in C
10.1.
C
11.
8. Misc Operators in C
11.1.
C
12.
Unary, Binary, and Ternary Operators in C
13.
Operator Precedence and Associativity in C
14.
Frequently Asked Questions
14.1.
What is the == operator in C?
14.2.
What is the use of Operators in C programming?
14.3.
How many operators can C have?
14.4.
What is the difference between the ‘=’ and ‘==’ operators?
15.
Conclusion
Last Updated: Mar 26, 2025
Easy

Operators in C Programming

Author Nikunj Goel
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Operators in C programming are essential for performing various operations on data, including arithmetic, logical, and relational comparisons. Operators in C help manipulate variables and values efficiently, making them a fundamental concept in programming. This article explores different operators in C programming, their types, functionalities, and practical examples to enhance understanding and improve coding efficiency.

Operators in C

What are Operators in C?

Operators in C are the fundamental elements that drive logic and computation within programs. They are crucial for performing operations like arithmetic, comparison, logical operations, etc., and form the backbone of decision-making and problem-solving in programming. 

For example 

c = a + b;

Here, ‘+’ is the operator known as the addition operator, and ‘a’ and ‘b’ are operands. The addition operator tells the compiler to add both of the operands ‘a’ and ‘b’. To dive deeper into how operators are used with data structures, 

Types of Operators in C :

  1. Arithmetic Operators
  2. Relational Operators
  3. Bitwise Operators
  4. Shift Operators
  5. Ternary or Conditional Operators
  6. Logical Operators
  7. Assignment Operators
  8. Misc Operators

Let's discuss them in detail:

1. Arithmetic Operators in C

Arithmetic operators perform basic mathematical operations: addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). These operators are used to calculate and manipulate numerical values in programming and mathematical expressions.

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulus (Remainder)a % b

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 10, b = 5;
printf("Addition: %d\n", a + b);
printf("Subtraction: %d\n", a - b);
printf("Multiplication: %d\n", a * b);
printf("Division: %d\n", a / b);
printf("Modulus: %d\n", a % b);
return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

 Arithmetic Operators in C

2. Relational Operators in C

 Relational operators compare two values or expressions:

  1. Equal to (==): Checks if two values are the same.
  2. Not equal to (!=): Checks if two values are different.
  3. Greater than (>): Checks if the left value is larger.
  4. Less than (<): Checks if the left value is smaller.
  5. Greater than or equal to (>=): Checks if the left value is larger or equal.
  6. Less than or equal to (<=): Checks if the left value is smaller or equal.

These operators return a boolean value (true or false) and are essential for controlling the flow of programs using conditional statements like if, while, and for loops.

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

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 5, b = 10;
printf("%d == %d is %d\n", a, b, a == b);
printf("%d != %d is %d\n", a, b, a != b);
printf("%d > %d is %d\n", a, b, a > b);
printf("%d < %d is %d\n", a, b, a < b);
printf("%d >= %d is %d\n", a, b, a >= b);
printf("%d <= %d is %d\n", a, b, a <= b);
return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Relational Operators in C

3. Bitwise Operators in C

Bitwise operators are used to perform operations at the bit level. Bitwise operators perform operations on the binary representations of integers. They include AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). These operators manipulate individual bits within integer values, enabling low-level data processing, such as setting, clearing, and toggling specific bits, commonly used in system programming and performance-critical applications.

OperatorDescriptionExample
&Bitwise ANDa & b
``Bitwise OR
^Bitwise XORa ^ b
~Bitwise NOT~a
<<Left shifta << b
>>Right shifta >> b

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 5, b = 3;
printf("%d & %d is %d\n", a, b, a & b);
printf("%d | %d is %d\n", a, b, a | b);
printf("%d ^ %d is %d\n", a, b, a ^ b);
printf("~%d is %d\n", a, ~a);
printf("%d << %d is %d\n", a, b, a << b);
printf("%d >> %d is %d\n", a, b, a >> b);
return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

itwise Operators in C

4. Shift Operators in C

Shift operators, like << (left shift) and >> (right shift), move bits left or right. x << 2 shifts the bits of x two positions to the left.

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 8; // Binary: 1000

printf("%d << 2 is %d\n", a, a << 2); // Left shift by 2: Binary 100000
printf("%d >> 2 is %d\n", a, a >> 2); // Right shift by 2: Binary 10

return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Shift Operators in C

5. Ternary or Conditional Operators in C

The ternary operator (? :) provides a concise way to express conditional statements. It evaluates a condition and returns one of two values based on its truth.

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 5, b = 3;
int max = (a > b) ? a : b;

printf("The maximum is %d\n", max);

return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Ternary or Conditional Operators

6. Logical Operators in C

Logical operators, including && (AND), || (OR), and ! (NOT), are used in Boolean expressions. x && y is true if both x and y are true.

OperatorDescriptionExample
&&Logical ANDa && b
` `
!Logical NOT!a

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 1, b = 0;

if (a && b) {
printf("Both conditions are true.\n");
} else {
printf("At least one condition is false.\n");
}

return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Logical Operators in C

7. Assignment Operators in C

Assignment operators, like +=, -=, *=, etc., combine assignment with other operations. a += 5 is a shorthand for a = a + 5.

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 5;
a += 3; // Equivalent to a = a + 3
printf("The value of a is %d\n", a);

return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Assignment Operators in C

8. Misc Operators in C

The sizeof operator returns the size, in bytes, of a variable or data type. The comma operator allows multiple expressions in a single statement, evaluating them from left to right.

For example:

  • C

C

#include <stdio.h>

int main() {
int a = 5;
printf("The size of 'a' is %lu bytes\n", sizeof(a));
printf("The address of 'a' is %p\n", (void*)&a);

return 0;
}
You can also try this code with Online C Compiler
Run Code

Output:

Misc Operators in C

Unary, Binary, and Ternary Operators in C

In C programming, operators can be classified based on the number of operands they act upon:

1. Unary Operators: These operators work with a single operand. Common examples include:

  • Increment (++) and Decrement (--): Increase or decrease the value of a variable by one.
  • Negation (-): Converts a positive value to negative and vice versa.
  • Logical NOT (!): Inverts the truth value of a condition.

2. Binary Operators: These operate on two operands and are further categorized into:

  • Arithmetic Operators: Perform basic mathematical operations like addition (+), subtraction (-), multiplication (*), and division (/).
  • Relational Operators: Compare two values, e.g., > (greater than), < (less than).
  • Logical Operators: Combine conditions using AND (&&), OR (||).

3. Ternary Operator: The only ternary operator in C is the conditional operator (?:). It takes three operands and evaluates a condition to decide which value to return.

Operator Precedence and Associativity in C

PrecedenceOperatorsDescriptionAssociativity
1(), [], ->, .Parentheses, Array Subscript, Arrow Operator, Member AccessLeft to Right
2++, --, +, -, !, ~, *, &, (type), sizeofIncrement/Decrement, Unary Plus/Minus, Logical NOT, Bitwise NOT, Dereference, Address-of, Type Casting, SizeofRight to Left
3*, /, %Multiplication, Division, ModulusLeft to Right
4+, -Addition, SubtractionLeft to Right
5<<, >>Bitwise Left Shift, Bitwise Right ShiftLeft to Right
6<, <=, >, >=Relational Operators (Less than, Greater than, etc.)Left to Right
7==, !=Equality OperatorsLeft to Right
8&Bitwise ANDLeft to Right
9^Bitwise XORLeft to Right
10&&Logical ANDLeft to Right
11?:Ternary Operator (Conditional Expression)Right to Left
12=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, `=`Assignment Operators
13,Comma OperatorLeft to Right

This table helps in understanding how expressions are evaluated in C programming. Operators with higher precedence are evaluated first, and in case of equal precedence, associativity determines the order of execution.

Frequently Asked Questions

What is the == operator in C?

The == operator in C is used for equality comparison between two operands.

What is the use of Operators in C programming?

Operators in C programming are used to perform various operations on variables and values, such as arithmetic, logical, relational, and bitwise operations. They facilitate calculations, comparisons, and data manipulation, enabling effective control and functionality within the program.

How many operators can C have?

C has a wide range of operators, including arithmetic, relational, logical, bitwise, assignment, increment/decrement, conditional (ternary), and special operators. There are over 45 operators, each serving specific operations and functionalities in programming.

What is the difference between the ‘=’ and ‘==’ operators?

The = operator is an assignment operator used to assign a value to a variable, while the == operator is a relational operator used to compare two values for equality, returning true if they are equal and false otherwise.

Conclusion

In this article, we talked about operators in C programming. We explored arithmetic, relational, logical, bitwise, and assignment operators. These operators allow developers to perform calculations, compare values, make decisions, manipulate bits, and assign values to variables. Operators are crucial for writing efficient and effective C code, that enables developers to solve complex problems easily.

Live masterclass