Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Types of Operators in C: Roles, Usage & Best Practices 2025

By Rohan Vats

Updated on Feb 06, 2025 | 28 min read

Share:

Did you know? As per Statista, C is the world's 10th most popular programming language, right after C# and C++. Many developers choose it for its direct control over hardware resources, which makes it an excellent option for building everything from embedded devices to operating systems.

One reason behind C’s enduring appeal lies in how it handles core operations, known as operators. These form the basis for arithmetic, comparisons, and logical decisions in your code. If you skip understanding different types of operators in C, you risk hours of debugging or unexpected behavior.

This guide thoroughly explores all the types of operators in C, from arithmetic to bitwise, with practical examples you can try immediately. You'll have a strong foundation for writing cleaner, more effective C programs by the end.

What is an Operator, and What are its Types in C? 

Operators are symbols or keywords that tell you to carry out specific actions. For example, in the 'a + b' expression, the '+' operator directs the system to add the two operands, a and b. Operands can be variables, constants, or even entire expressions.

Understanding how different types of operators work is important for tasks such as arithmetic, comparisons, and pointer manipulation.

Below is a brief table showing the major types of operators in C:

Types of Operators in C

Usage

Few Example Symbols

Arithmetic  Performs basic math such as addition, subtraction, multiplication
  • +
  • -
  • *
  • /
  • %
Assignment Assigns or updates variable values
  • =
  • +=
  • -=
  • *=
  • /=
  • %=
Relational Compares values and returns a truth value
  • <
  • >
  • <=
  • >=
  • ==
  • !=
Logical Combines multiple conditions or inverts them
  • &&
  • ||
  • !
Bitwise Works directly on the binary representation of integers
  • &
  • |
  • ^
  • ~
  • <<
  • >>
Special Covers unique tasks like size checking, pointer access, and more
  • ?:
  • Sizeof
  • ,
  • .
  • ->

Up next, you’ll see how each operator type works in actual C programs, complete with examples you can test on your own.

What are the Different Types of Operators in C?

Operators in C go beyond basic math tasks. They handle comparisons, logical checks, data manipulation, and even pointer operations. Grouping them based on their purpose can help you plan and write code that’s easier to understand and maintain.

In the next sections, you'll see how each category works and examples showing why these operators are key to solving real coding challenges.

1. Arithmetic Operators

Arithmetic operators in C handle a range of numeric tasks, from simple addition and subtraction to finding remainders with the modulus operator (%). You can also increment or decrement a variable with ‘++’ and ‘--’, which is handy for loops or counters. 

These operators act on integer and floating-point data types, letting you combine multiple operations in a single expression. Knowing each one allows you to manage calculations more efficiently in your programs.

Here are the 9 types of arithmetic operators in C:

Symbol & Name

Purpose

Syntax*

+ (Addition) Adds two operands result = a + b;
- (Subtraction) Subtracts right operand from left operand result = a - b;
* (Multiplication) Multiplies two operands result = a * b;
/ (Division) Divides left operand by right operand result = a / b;
% (Modulus) Returns remainder after division result = a % b;
++ (Increment) Adds 1 to the operand ++a; or a++;
-- (Decrement) Subtracts 1 from the operand --a; or a--;
+ (Unary Plus) Indicates a positive value +a;
- (Unary Minus) Negates the operand -a;

*Please Note: In C, each statement ends with a semicolon (;). It’s simply a statement terminator that tells the compiler, “This line of code ends here.” For instance, when you write result = a + b;, the semicolon indicates that this assignment statement is complete.

Example of Arithmetic Operators in C

This sample program shows how to add, multiply, and find remainders, along with incrementing and decrementing variables. By observing how each operator modifies the values of ‘x’ and ‘y’, you can see how arithmetic operators streamline calculations in a straightforward way.

#include <stdio.h>

int main() {
    int a = 10, b = 3;
    
    // Unary Plus and Unary Minus
    int positiveA = +a;
    int negativeA = -a;
    
    // Basic Arithmetic
    int sum = a + b;
    int difference = a - b;
    int product = a * b;
    int quotient = a / b;
    int remainder = a % b;

    // Increment and Decrement
    a++;    
    b--;

    printf("Unary plus of a: %d\n", positiveA);
    printf("Unary minus of a: %d\n", negativeA);
    printf("Sum (a + b): %d\n", sum);
    printf("Difference (a - b): %d\n", difference);
    printf("Product (a * b): %d\n", product);
    printf("Quotient (a / b): %d\n", quotient);
    printf("Remainder (a %% b): %d\n", remainder);
    printf("After Increment, a: %d\n", a);
    printf("After Decrement, b: %d\n", b);

    return 0;
}

Output:

Unary plus of a: 10
Unary minus of a: -10
Sum (a + b): 13
Difference (a - b): 7
Product (a * b): 30
Quotient (a / b): 3
Remainder (a % b): 1
After Increment, a: 11
After Decrement, b: 2

Real-World Uses of Arithmetic Operators

Use Case

Common Scenario

Operators in Action

Financial Calculations Calculating totals, discounts, or interest in billing systems.

+-*/

Gaming Mechanics Tallying scores, tracking lives, or updating player stats.

++ for counters, += for scores

Data Analysis Summing arrays, averaging values, or finding remainders.

+/%

Loops and Iterations Incrementing or decrementing loop variables.

++--

Geometry and Trigonometry Computing areas, perimeters, or angles in real-time. */% (for specific needs)

Also Read: What is Array in C? With Examples

2. Assignment Operators

Assignment operators in C help you store or update the value of a variable. The most basic form is =, which assigns the right-hand value to the left-hand variable. Beyond that, compound assignment operators like += or -= combine arithmetic and assignment in one step. This can reduce code repetition and make expressions more concise.

Below is a look at all the 11 assignment operator types you might encounter in the C programming language.

Symbol & Name

What It Does

Syntax

= (Simple Assignment) Places the right-hand value into the left-hand variable. a = b;
+= (Add and Assign) Adds the right-hand value to the variable, then stores the sum in that variable. a += b;
-= (Subtract and Assign) Subtracts the right-hand value from the variable, then stores the result. a -= b;
*= (Multiply and Assign) Multiplies the variable by the right-hand value, then stores the result. a *= b;
/= (Divide and Assign) Divides the variable by the right-hand value, then stores the result. a /= b;
%= (Modulus and Assign) Performs modulus with the right-hand value, then stores the remainder. a %= b;
<<= (Left Shift and Assign) Shifts bits to the left, then stores the shifted value. a <<= b;
>>= (Right Shift and Assign) Shifts bits to the right, then stores the shifted value. a >>= b;
&= (Bitwise AND and Assign) Performs a bitwise AND, then stores the result. a &= b;
|= (Bitwise OR and Assign) Performs a bitwise OR, then stores the result. a |= b;
^= (Bitwise XOR and Assign) Performs a bitwise XOR, then stores the result. a ^= b;

Example of Assignment Operators in C

The following program shows all 11 types of assignment operators in action. You’ll see how they modify a variable’s value step by step, including simple arithmetic and bitwise changes.

#include <stdio.h>

int main() {
    int a = 10, b = 3;

    // Simple Assignment
    printf("Initial value of a: %d\n", a);

    // Add and Assign
    a += b; // a = a + b
    printf("After a += b, a: %d\n", a);

    // Subtract and Assign
    a -= b; // a = a - b
    printf("After a -= b, a: %d\n", a);

    // Multiply and Assign
    a *= b; // a = a * b
    printf("After a *= b, a: %d\n", a);

    // Divide and Assign
    a /= b; // a = a / b
    printf("After a /= b, a: %d\n", a);

    // Modulus and Assign
    a %= b; // a = a % b
    printf("After a %%= b, a: %d\n", a);

    // Reset a to 10 for bitwise operations
    a = 10;

    // Left Shift and Assign
    a <<= 1; // a = a << 1
    printf("After a <<= 1, a: %d\n", a);

    // Right Shift and Assign
    a >>= 1; // a = a >> 1
    printf("After a >>= 1, a: %d\n", a);

    // Reset a to 10 for bitwise AND
    a = 10;
    a &= b; // a = a & b
    printf("After a &= b, a: %d\n", a);

    // Reset a to 10 for bitwise OR
    a = 10;
    a |= b; // a = a | b
    printf("After a |= b, a: %d\n", a);

    // Reset a to 10 for bitwise XOR
    a = 10;
    a ^= b; // a = a ^ b
    printf("After a ^= b, a: %d\n", a);

    return 0;
}

Output: 

Initial value of a: 10
After a += b, a: 13
After a -= b, a: 10
After a *= b, a: 30
After a /= b, a: 10
After a %= b, a: 1
After a <<= 1, a: 20
After a >>= 1, a: 10
After a &= b, a: 2
After a |= b, a: 11
After a ^= b, a: 9

Real-World Uses of Assignment Operators

Use Case

Typical Scenario

Operators in Action

Updating Counters Keeping track of loop iterations or counts in programs a += 1; or a -= 1;
Accumulating Totals Maintaining running sums or aggregates total += newValue;
Bitwise Flags Managing status bits (e.g., feature toggles) `flags
Modifying Large Arrays Scaling or adjusting array elements in numeric projects array[i] *= scaleFactor;
Networking Protocols Shifting and masking bits for data packet handling header <<= 1; header &= mask;

3. Relational Operators

Relational operators compare two operands and return either 1 (true) or 0 (false). You’ll see them in conditional statements, loops, and any code that checks whether values match certain criteria.

They can help validate user input, ensure ranges are met, or detect whether one piece of data exceeds another. By mastering these types of operators, you’ll have more control over logical flows and decision-making in your programs.

Here’s an overview of all the 6 types of relational operators in C:

Symbol & Name

What It Does

Syntax

< (Less Than) Returns 1 if left operand is smaller than right result = a < b;
> (Greater Than) Returns 1 if left operand is larger than right result = a > b;
<= (Less or Equal) Returns 1 if left operand is smaller or equal to right result = a <= b;
>= (Greater or Equal) Returns 1 if left operand is larger or equal to right result = a >= b;
== (Equal To) Returns 1 if both operands have the same value result = a == b;
!= (Not Equal To) Returns 1 if both operands have different values result = a != b;

Example of Relational Operators in C

The following program checks various conditions on two integers and prints whether those conditions are true or false. This helps illustrate how each relational operator can be used for comparisons in everyday coding tasks.

  • x < y checks if x is strictly less than y.
  • x > y checks if x is strictly greater than y.
  • x <= y checks if x is less than or equal to y.
  • x >= y checks if x is greater than or equal to y.
  • x == y checks if both operands have the same value.
  • x != y checks if the two operands have different values.
#include <stdio.h>

int main() {
    int x = 10, y = 3;
    printf("x < y  : %d\n", x < y);
    printf("x > y  : %d\n", x > y);
    printf("x <= y : %d\n", x <= y);
    printf("x >= y : %d\n", x >= y);
    printf("x == y : %d\n", x == y);
    printf("x != y : %d\n", x != y);

    return 0;
}

Output: 

x < y  : 0
x > y  : 1
x <= y : 0
x >= y : 1
x == y : 0
x != y : 1

Real-World Uses of Relational Operators

Use Case

Typical Scenario

Operators in Action

Validation Checks Ensuring a user’s age is above a certain limit if (age >= 18)
Loop Conditions Running a loop until a value exceeds a threshold while (count < limit)
Sorting Algorithms Comparing elements for sorting in ascending or descending order if (arr[i] > arr[j])
Exam Scoring Checking if a student’s marks meet the pass mark if (marks >= passMark)
Inventory Thresholds Triggering alerts if stock falls below a reorder level if (stock <= minReq)

You can also check out upGrad’s tutorial, ‘For Loop in C’. Discover how the loop works, its types, syntax, and more.

4. Logical Operators

Logical operators in C let you combine or invert multiple conditions in a single expression. 

  • They return 1 (true) when the condition holds and 0 (false) otherwise. 
  • You can check multiple constraints with logical AND (&&) or logical OR (||)
  • You can flip a condition’s outcome using logical NOT (!). 

These types of operators in C are essential in loops, conditional statements, and error-handling routines because they give you greater control over the flow of your program. They also help you write clearer, more readable conditions instead of nesting numerous if-else blocks.

Here are the 3 types of logical operators in C:

Symbol & Name

What It Does

Syntax

&& (Logical AND) Returns 1 if both conditions are true, else 0 result = condition1 && condition2;
|| (Logical OR) Returns 1 if at least one condition is true, else 0 result = condition1 || condition2;
! (Logical NOT) Reverses a condition’s value: true becomes false, and vice versa result = !condition;

Example of Logical Operators in C

The following program shows how each logical operator works by evaluating conditions on two integers. You’ll see how combining checks can simplify decision-making and reduce multiple nested if statements.

  • x < 10 && y > 5 checks if x is less than 10 and y is greater than 5.
  • x > 10 || y == 10 checks if x is greater than 10 or y equals 10.
  • !(x < y) flips the outcome of (x < y). If (x < y) is true, adding ! makes it false.
#include <stdio.h>

int main() {
    int x = 5, y = 10;
    
    // Logical AND
    printf("x < 10 && y > 5  : %d\n", (x < 10) && (y > 5));
    
    // Logical OR
    printf("x > 10 || y == 10: %d\n", (x > 10) || (y == 10));
    
    // Logical NOT
    printf("!(x < y)         : %d\n", !(x < y));
    
    return 0;
}

Output: 

x < 10 && y > 5  : 1
x > 10 || y == 10: 1
!(x < y)         : 0

Real-World Uses of Logical Operators

Use Case

Typical Scenario

Operators in Action

Form Validation Checking multiple fields (e.g., name not empty and age valid) (nameNotEmpty && ageValid)
Search Filters Displaying results that match any of several criteria (color == "Red") || (size == 'M') || (brand == "Nike")
Loop Conditions Continuing a loop only if multiple conditions stay true while (count < max && balance > 0)
Error Handling Inverting error flags to simplify logic if (!errorFlag)
Feature Toggles Combining flags to enable or disable certain features if (isBetaUser && !isFeatureLocked)

5. Bitwise Operators

Bitwise operators in C revolve around the binary representation of integers, letting you manipulate individual bits directly. They can be pivotal for tasks like controlling hardware registers, toggling flags, or compressing multiple settings into a single variable. 

You can perform quick calculations or implement simple encryption by shifting, combining, or flipping bits. Each operator tackles bits differently: some merge bits from two operands, while others shift them left or right, or invert them altogether. 

Mastering the different types of operators in the Bitwise category can lead to more efficient and compact code in resource-constrained projects.

Here are the 6 types of Bitwise operators explained:

Symbol & Name

What It Does

Syntax

& (Bitwise AND) Compares each bit of two operands and returns 1 if both bits are 1 result = a & b;
| (Bitwise OR) Returns 1 for each bit position where at least one operand has a 1 result = a | b;
^ (Bitwise XOR) Returns 1 for each bit position where bits differ between the two operands result = a ^ b;
~ (Bitwise NOT) Flips every bit of the operand result = ~a;
<< (Left Shift) Moves bits to the left by the specified amount, filling vacant bits with 0 result = a << b;
>> (Right Shift) Moves bits to the right by the specified amount, filling vacant bits with 0 (in most compilers) result = a >> b;

Example of Bitwise Operators in C

The following code demonstrates how bitwise operations in C affect the binary representation of two integers. You can see how each operator changes the bits, which is critical for tasks like flag management or fast calculations in embedded programming.

  • x & y performs a bitwise AND on 0101 and 0011.
  • x | y performs a bitwise OR on 0101 and 0011.
  • x ^ y is a bitwise XOR, which is 1 for bits that differ.
  • ~x flips all bits in x.
  • x << 1 shifts bits of x to the left by 1, adding a 0 on the right.
  • x >> 1 shifts bits of x to the right by 1, typically inserting a 0 on the left.
#include <stdio.h>

int main() {
    int x = 5, y = 3; // In binary: x = 0101, y = 0011

    printf("x & y: %d\n", x & y);
    printf("x | y: %d\n", x | y);
    printf("x ^ y: %d\n", x ^ y);
    printf("~x  : %d\n", ~x);
    printf("x << 1: %d\n", x << 1);
    printf("x >> 1: %d\n", x >> 1);

    return 0;
}

Output: 

x & y: 1
x | y: 7
x ^ y: 6
~x  : -6
x << 1: 10
x >> 1: 2

Real-World Uses of Bitwise Operators

Use Case

Typical Scenario

Operators in Action

Encryption Performing XOR-based operations on data encrypted = plain ^ key;
Checksum Calculating simple checks by shifting and combining bits checksum ^= data << shift;
Graphics Manipulating pixel data at the bit level pixelValue & colorMask;

6. Special Types of Operators in C 

Beyond arithmetic, relational, logical, bitwise, and assignment types of operators, C includes a range of specialized ones that handle memory addresses, structure references, and more advanced tasks. 

Let’s explore each special C operator in detail.

Conditional Operator in C

The conditional operator offers a compact way to handle simple decision-making in your programs. It evaluates a condition and selects one of two expressions based on whether the condition is true or false. 

Unlike an if-else statement, which spans multiple lines, the conditional operator fits into a single expression, often making code more concise. It can streamline tasks such as choosing between two values, setting defaults, or performing quick validations. 

Because it involves three operands — a condition and two results — it’s the only operator in C that requires three parts.

Here are the crucial details of conditional operator in C:

Aspect Details
Name of the Operator Conditional operator aka Ternary operator
Symbol of the Operator ?:
Syntax of the Operator result = (condition) ? expression_if_true : expression_if_false;

Example of Conditional Operator in C

Here’s a short program illustrating how it decides between two values based on a logical check:

  • The condition (score >= 40) checks whether the score is 40 or above.
  • If true, it picks "Pass". Otherwise, it picks "Fail".
  • The chosen string is stored in the result, which is then printed.
#include <stdio.h>

int main() {
    int score = 75;
    const char* result = (score >= 40) ? "Pass" : "Fail";
    
    printf("Exam Result: %s\n", result);
    return 0;
}

Output: 

Exam Result: Pass

Uses of the Conditional Operator

Use

Description

Replacing Simple if-else Quickly pick one of two values without writing multiple lines of conditional code
Setting Defaults Assign a fallback value if a main condition isn’t met
Choosing Min/Max Compare two numbers and select the smaller or larger one in a single expression
Inline Validations Verify a condition on the fly before deciding what to store or display

sizeof Operator in C

The sizeof operator in C tells you how much memory a data type or variable needs, measured in bytes. It’s evaluated during compilation, so it doesn’t slow down your program at runtime. 

You might use sizeof to determine array lengths, allocate memory dynamically, or confirm that certain data types meet specific size requirements. Because C implementations can vary in how many bytes they assign to each type, sizeof is one of the most reliable ways to ensure consistent, portable code.

Here are the crucial details about sizeof operator in C:

Aspect

Details

Name of the Operator sizeof Operator
Symbol of the Operator sizeof
Syntax of the Operator sizeof(type or variable)
Return Value Unsigned integer (type size_t)

Example of sizeof Operator in C

Here’s a brief program that prints the sizes of common data types:

  • Each call to sizeof checks how many bytes the data type occupies in the current environment.
  • %zu is the recommended format specifier for variables of type size_t.
#include <stdio.h>

int main() {
    printf("Size of int: %zu bytes\n", sizeof(int));
    printf("Size of float: %zu bytes\n", sizeof(float));
    printf("Size of double: %zu bytes\n", sizeof(double));
    printf("Size of char: %zu byte\n", sizeof(char));
    return 0;
}

Output:

Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte

Uses of the sizeof Operator

Use

Description

Portable Coding Verifying data type sizes across different compilers or platforms
Array Length Calculations Determining the number of elements by dividing total bytes by sizeof(elementType)
Low-Level System Programming Checking structure alignment and padding for performance or hardware constraints

Comma Operator in C

The comma operator allows multiple expressions to be evaluated and executed in a single statement. Despite looking similar to the commas that separate function parameters, it works differently by evaluating each expression from left to right and returning the value of the last expression. 

This operator in C can simplify code when you want to combine related tasks in one place, such as initializing multiple variables in a loop. Keep in mind that each expression is evaluated in sequence, but intermediate results are not stored unless explicitly assigned.

Here are the critical details about the comma operator in C programming: 

Aspect

Details

Name of the Operator Comma Operator
Symbol of the Operator ,
Syntax of the Operator (expression1, expression2, ..., expressionN)
Execution Order Left to right, final value is that of the last expression

Example of Comma Operator in C

Below is a program that uses the comma operator to initialize and update multiple variables in a single line:

  • b is assigned the value 2.
  • c is then set to b + 3, which becomes 5.
  • Finally, c * 2 is computed (5 * 2 = 10) and assigned to a.
#include <stdio.h>

int main() {
    int a, b, c;
    a = (b = 2, c = b + 3, c * 2); 
    // Here, b is set to 2, c becomes 5, and finally a is assigned c * 2 = 10

    printf("a: %d\n", a);
    printf("b: %d\n", b);
    printf("c: %d\n", c);

    return 0;
}

Output: 

a: 10
b: 2
c: 5

Uses of the Comma Operator

Use

Description

Combining Expressions in Loops Efficiently update multiple variables in the loop control part, like in for (i=0, j=10; i<j; i++, j--)
Assigning Multiple Values in One Go Evaluate and assign different values in a single statement
Chaining Calculations Run smaller expressions sequentially, returning the last one’s result in assignments
Minimizing Lines of Code Merge related operations together without extra statements

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

Dot (.) and Arrow (->) Operators in C

The dot (.) and arrow (->) operators help you access members within structures and unions. 

  • The dot operator works directly on an instance of a structure, letting you retrieve or set a specific field. 
  • The arrow operator, on the other hand, is used when you have a pointer to a structure: it dereferences the pointer and then accesses the member. 

Both these types of operators make it easier to handle complex data types by cleanly referring to individual elements without cluttering your code with extra dereferencing steps. In many data structures — like linked lists or trees — these operators come into play frequently.

Here are some important details about these two types of operators:

Aspect

Details

Name of the Operators Dot Operator, Arrow Operator
Symbol of the Operators . for direct structure access, -> for pointer-to-structure access
Syntax of the Operators structureInstance.member or pointerToStructure->member

Example of Dot and Arrow Operators in C

Below is a simple program showing how both operators are used with a structure and a pointer to that structure:

  • p1 is a structure of type Point with x = 10 and y = 20.
  • ptr stores the address of p1.
  • p1.x and p1.y directly access the members of p1.
  • ptr->x and ptr->y dereference ptr and then access the members, equivalent to (*ptr).x and (*ptr).y.
#include <stdio.h>

struct Point {
    int x;
    int y;
};

int main() {
    struct Point p1 = {10, 20};
    struct Point* ptr = &p1;

    // Using the dot operator
    printf("p1.x using dot: %d\n", p1.x);
    printf("p1.y using dot: %d\n", p1.y);

    // Using the arrow operator
    printf("ptr->x using arrow: %d\n", ptr->x);
    printf("ptr->y using arrow: %d\n", ptr->y);

    return 0;
}

Output:

p1.x using dot: 10
p1.y using dot: 20
ptr->x using arrow: 10
ptr->y using arrow: 20

Uses of Dot (.) and Arrow (->) Operators in C

Use

Description

Accessing Struct Members Directly Retrieve or set fields using the dot operator on an actual structure
Accessing Struct Members via Pointer Dereference pointers to structures with the arrow operator for cleaner code
Linked List Manipulation Move through node pointers (current->next) and access node data
Object-Like Operations Simulate object member access in C when working with more complex structs

Address-of (&) and Dereference (*) Operators in C

Pointers are a powerful feature in C, and the address-of (&) and dereference (*) operators lie at the heart of this mechanism. 

  • The & operator retrieves the memory address of a variable, turning it into a pointer. 
  • Meanwhile, the * operator (used on a pointer) grants access to the data at that address.

By combining these two types of operators, you can work with memory directly, which is helpful for tasks like dynamic memory allocation, creating complex data structures, or passing large data efficiently. Although they might seem tricky at first, a solid grasp of & and * is key to writing flexible and optimized code in C.

Here are some key details you should know:

Aspect

Details

Name of the Operators Address-of Operator, Dereference Operator
Symbol of the Operators & for address-of,for dereference
Syntax of the Operators

pointer = &variable;

value = *pointer;

Example of Address-of (&) and Dereference (*) Operators in C

Below is a simple program to show how to take a variable’s address, store it in a pointer, and then use dereferencing to access the original data:

  • int *ptr = &num; takes the address of num and stores it in the pointer ptr.
  • *ptr gives the value at the address held by ptr, effectively letting you read or write num via ptr.
  • Changing *ptr updates num because both refer to the same memory location.
#include <stdio.h>

int main() {
    int num = 42;
    int *ptr = &num; // Address-of operator used to get num's address

    printf("Address of num: %p\n", (void*)&num);
    printf("Value of ptr (which is &num): %p\n", (void*)ptr);
    printf("Value pointed to by ptr (*ptr): %d\n", *ptr);

    // Modifying the value via pointer
    *ptr = 100;
    printf("Updated value of num after *ptr = 100: %d\n", num);

    return 0;
}

Output:

Address of num: 0x7ffeea7ac9bc      // Example address; will vary
Value of ptr (which is &num): 0x7ffeea7ac9bc
Value pointed to by ptr (*ptr): 42
Updated value of num after *ptr = 100: 100

Uses of Address-of (&) and Dereference (*) Operators

Use

Description

Dynamic Memory Management Using & with malloc or other allocation functions to manage data on the heap.
Passing Large Structures by Reference Avoiding copying large data by passing pointers to functions instead of entire structures.
Building Linked Data Structures Linking nodes in a linked list or tree by storing addresses in pointers.
Modifying Variables from Functions Allowing functions to change the original variable using a pointer parameter.

Operator Precedence and Associativity in C

Operator precedence and associativity determine the order in which parts of an expression are evaluated. When multiple operators appear in the same statement, precedence dictates which operator runs first, and associativity decides how operators of the same level group together. 

Being aware of these rules prevents unexpected results, especially in complex expressions. It also helps you write clearer code: well-placed parentheses can override default precedence, making your intent obvious to both the compiler and anyone reading your work. 

Below is a streamlined overview that shows how operators stack up in priority.

Operator Group

Examples

Associativity

Highest Precedence ()[]->. Left to Right
Unary Operators ++--!~&*(type) Right to Left
Multiplicative */% Left to Right
Additive +- Left to Right
Relational and Equality <><=>===!= Left to Right
Logical AND / OR &&|| Left to Right
Conditional ?: Right to Left
Assignment =+=-=*=/=%=, etc. Right to Left
Lowest Precedence , (Comma operator) Left to Right

Example of Operator Precedence and Associativity in C

Here’s a program that demonstrates how precedence and associativity can affect an expression’s outcome. Changing parentheses can lead to different results if you’re not careful.

  • a + b * c follows precedence rules: b * c happens first, giving 3 * 4 = 12, then 2 + 12 = 14.
  • (a + b) * c uses parentheses to change the order, so a + b becomes 5, then multiplied by c = 4, resulting in 20.
#include <stdio.h>

int main() {
    int a = 2, b = 3, c = 4;
    int result1 = a + b * c;       // Multiplication first, then addition
    int result2 = (a + b) * c;     // Parentheses override default precedence

    printf("Without parentheses: %d\n", result1);
    printf("With parentheses   : %d\n", result2);

    return 0;
}

Output:

Without parentheses: 14
With parentheses   : 20

Uses of Operator Precedence and Associativity

Use

Description

Writing Complex Expressions Preventing ambiguous operations by applying parentheses where needed
Avoiding Logic Errors Ensuring that tricky combinations (like ++a + b++) behave as intended
Code Readability Highlighting the intended evaluation sequence for others who read your code
Mathematical Calculations Correctly handling multiple operations (e.g., mix of arithmetic, bitwise, and logical)
Simplifying Debugging Reducing the chance of subtle errors by making operator order explicit

Unary, Binary, and Ternary Operators in C

Operators in C are often described by how many operands they work with. 

  • A unary operator needs one operand
  • A binary operator works with two
  • A ternary operator uses three. 

Understanding these categories clarifies how different operators function and helps you choose the most appropriate one for a given task.

Here are some crucial details:

Number of Operands

Examples

1 (Unary) ++a--a!a~a
2 (Binary) a + ba - ba & b`a
3 (Ternary) (condition) ? expression1 : expression2

Example Demonstrating Unary, Binary, and Ternary Types of Operators

Below is a simple program that shows how these three categories of operators can appear in a single piece of code:

  • Unary Operator (++a): Increases the value of a by 1, changing it from 5 to 6.
  • Binary Operator (a + b): Adds the new a (6) and b (3), giving 9.
  • Ternary Operator ((a > b) ? a : b): Checks if a is greater than b. Since 6 > 3 is true, it returns a.
#include <stdio.h>

int main() {
    int a = 5, b = 3;

    // Unary: Increment 'a'
    ++a; // a becomes 6

    // Binary: Add 'a' and 'b'
    int sum = a + b; // 6 + 3 = 9

    // Ternary: Check which is bigger
    int bigger = (a > b) ? a : b; // evaluates to 6

    printf("After unary increment, a: %d\n", a);
    printf("Sum of a and b: %d\n", sum);
    printf("Bigger number: %d\n", bigger);

    return 0;
}

Output:

After unary increment, a: 6
Sum of a and b: 9
Bigger number: 6

Uses of Unary, Binary, and Ternary Operators

Operator Type

Typical Scenarios

Unary Incrementing loop counters, negating numbers, checking logical NOT
Binary Arithmetic operations (+, -), bitwise manipulation (&`)
Ternary Quick branching in a single expression, choosing one of two values based on a condition

What are Some Common Mistakes to Avoid When Using Operators in C?

Even seasoned programmers encounter errors when working with operators in C. Avoiding these pitfalls can save time and ensure your program behaves as expected.

Below are common mistakes you should watch out for when working with different types of operators in C.

  • Incorrect Operator Precedence: Forgetting precedence rules can lead to unexpected results. Always use parentheses to clarify the order of operations.
  • Misuse of Assignment Operator (=) and Relational Operator (==): Confusing these operators can cause logic errors, especially in conditional statements.
  • Division by Zero: Performing division without checking for zero results in runtime errors.
  • Mismatched Data Types: Using incompatible data types can lead to truncation or unexpected behavior.
  • Overusing Increment and Decrement Operators: Using ++ or -- multiple times in a single expression can confuse the logic and readability of your code.
  • Ignoring Type Conversions: Implicit type conversions can lead to precision loss or data corruption. Use explicit casting to control conversions.
  • Incorrect Use of Logical Operators: Misusing && and || can result in faulty condition evaluations.

Avoiding these mistakes ensures your code is both accurate and maintainable. This sets the stage for implementing best practices to write efficient C programs.

What Are Some Best Practices for Writing Clean and Efficient Code in C?

Writing clean and efficient code involves a combination of smart operator usage and optimization techniques. Following best practices simplifies debugging and enhances code performance.

Below are practical tips for working with types of operators in C and writing efficient code.

  • Choose Operators Wisely: Use the most appropriate operator for the task. For example, prefer bitwise operators for low-level programming tasks.
  • Make Use of Special Operators in C Programming: Operators like sizeof and conditional operators can simplify complex tasks and reduce redundancy.
  • Use Parentheses for Clarity: Parentheses override default precedence and make expressions more readable.
  • Optimize Performance with Bitwise Operators: Bitwise operations are faster and use fewer resources than arithmetic operations in certain scenarios.
  • Avoid Deeply Nested Conditions: Refactor nested conditions using ternary or logical operators to enhance readability.
  • Comment Complex Expressions: Document intricate logic to help others understand your code quickly.
  • Minimize Side Effects: Avoid using operators like ++ or -- in complex expressions, as they can introduce hidden bugs.
  • Test for Boundary Conditions: Ensure operators behave correctly at edge cases, such as large numbers or zero values.

Also Read: How to Become a Software Engineer in India? 7 Actional Steps

How Can upGrad Help You?

If you aim to deepen your understanding of programming and advance your career, upGrad is here to guide you. With over 10 million learners worldwide, 200+ expertly designed courses, and partnerships with 1400+ hiring companies, upGrad equips you with the knowledge and skills needed to thrive in a competitive environment.

Below are some courses from upGrad that align with mastering all types of operators in C and programming fundamentals.

You also have access to personalized one-on-one expert career counseling. These sessions help you identify your goals, improve your resume, and craft a career strategy tailored to your skills.

Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.

Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.

Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.

Reference Links: 
https://www.statista.com/statistics/793628/worldwide-developer-survey-most-used-languages/

Frequently Asked Questions (FAQs)

1. What are the 6 relational operators in C?

2. What are the 6 logical operators?

3. Who is the father of the C language?

4. What is #include in C?

5. What are the 3 operators?

6. What are the different operator types in Python?

7. What is bitwise or operator?

8. What is a pointer in C?

9. How to use Boolean?

10. What is an operand in C?

11. What is ‘for’ used for in C?

Rohan Vats

419 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

Suggested Blogs