Udemy logo

c operatorsAn operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. They are used in programs to manipulate data and variables. The C language has built-in operators and can be classified into a number of categories.

Learn more about the C language at Udemy.com

Arithmetic Operators

C provides all the basic arithmetic operators.

An Example of Arithmetic Operators

void main()
int number1, number2,number3;
int sum1,multi,divi,difference;
printf(“Enter two numbers \n”);
scanf(“%d”,&number2);      //number1=10,number2=5,number3=20
printf(“Addition is %d”sum1);
printf(“Subtraction is %d”,difference);
printf(“Multiplication is %d”,multi);
printf(“Division is  %d”,div);


Addition is 35

Subtraction is 5

Multiplication is 1000

Division is 2

Relational Operator

These operators are used in making a comparison between two quantities or take certain decisions. For instance, a relational operator compares the age of two people or the price of two items.

a<b or a<30 is called relational expression and the value is either one or zero or true or false, respectively.

For example:

10 < 40 is true. While 20>240 is false.

Different operators are:

An example:

4<=10 True
4<=-10 False
10==10 True

a+b=d+g only if the sum of values of a and b is equal to the sum of g and d.

An arithmetic expression can be used on either side of the relational operator. In this case, an arithmetic expression is evaluated first on either side and then the result is evaluated.

Master C programming with a class at Udemy.com

Logical Operators

Logical operators are used to evaluate complex regular expressions and are used in combinations with relational operators to test one or more conditions and make decisions. C has three logical operators:

An Example:

a>    b&& x==20

The above expression is a combination of two-relational expressions and is termed as logical expression.  A logical expression also yields a value of one or zero. For instance, the above expression is true when both the condition a>b and x==20 is True.

Some Examples of logical expressions:

Assignment Operators

These operators are used to assign the result of an expression to a variable. C also has some shorthand assignment operators.

For Example: x=x+y+1 can be written in shorthand form x+=y+1. The shorthand operator += means “add y+1 to x’ or ‘increment x by y+1’.

If y=2 and x=1, then x after execution would become 5.

The advantages of using shorthand are:

Some Examples:

Increment Decrement Operators

C allows very useful operators that aren’t found generally in other languages. These are the increment(++) and decrement(–) operators.

The increment operator adds 1 to the operand, while decrement operator subtracts 1 and both these are unary operators.

These types are further divided into two sub divisions based on their functionality and they are:

In Postfix the value is first assigned to the variable on the left and it then increments the operand.


n=2 ;

The ‘y’ will hold 2 and the postfix first assigns the value and then increments it by one.

In Prefix, the value is incremented and then assigned.



The ‘y’ will hold 3 now.

Increment and decrement operators are unary operators and they require variables as their operands. The precedence and associativity of ++ and – operators are the same as that of unary + and unary –

Conditional Operator:

Ternary operator is a conditional operator available in C to construct conditional expressions of the form exp1? exp2:exp3

Here exp1, exp2,exp3 are the expressions.

The operator?: works as follows :

Exp1 is evaluated first. If true then exp2 is evaluated and becomes the value of the expression.If exp1 is false exp3 is evaluated and it is the value of the expression. Note that only one of the expressions after ‘?’ will be executed.

For Example:

x=(n>m) ? n:m;

Ternary operator works just like the If else statement.

Bitwise Operators:

C also provides the facility of changing information at bit levels. These operators are used to test the bits or shift them right or left. Bitwise operators cannot be applied to float and double i.e. decimal values.

Some of the operators are:


Special Operators

The C language supports special operators like comma and sizeof operators.

Comma Operator

Comma operator is used in linking all related expressions in a way where the comma links the list of the expressions evaluated from left to right and the rightmost expression shows the combined expression’s value.


In for Loop, for (n=1,m=10,n<=m; n++,m++).


In this example, it first assigns the value 11 to x and then assigns 10 to z and later assigns 21 to variable val. Parentheses are necessary since Comma has the least precedence as compared to all the other operators.

The sizeof operator:

The sizeof operator is compile time operator and it gives the size of the operands in the bytes it occupies. The operand can be a variable or a constant or a data type.


N=sizeof(long )

The size of operator helps to determine structure size when the programmer does not know the size. It also helps in dynamic memory allocation.

Learn more about the C language with a course at Udemy.com



Page Last Updated: May 2014

Top courses in C# (programming language)

Ultimate C# Masterclass for 2024
Krystyna Ślusarczyk
4.7 (3,153)
Complete C# Unity Game Developer 3D
Rick Davidson, GameDev.tv Team, Gary Pettie
4.7 (41,974)
The Unity C# Survival Guide
Jonathan Weinberger, Unity Technologies, GameDevHQ Team
4.8 (1,800)
.NET / C# Interview Questions with Answers.
Shivprasad Koirala
4.7 (1,729)
C#/.NET - 50 Essential Interview Questions (Mid Level)
Krystyna Ślusarczyk
5 (272)
Highest Rated
Complete C# Masterclass
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.5 (29,885)
Design Patterns in C# and .NET
Dmitri Nesteruk
4.6 (12,071)
C# 10 | Ultimate Guide - Beginner to Advanced | Master class
Web University by Harsha Vardhan
4.6 (3,748)

More C# (programming language) Courses

C# (programming language) students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.

Request a demo