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



Top courses in C#

C# .NET For Beginners
Rick Phillips
4.4 (1,267)
What's New in C#7, C#8 and C#9
Dmitri Nesteruk
4.6 (563)
Complete C# Unity Game Developer 3D
Ben Tristem, Rick Davidson, GameDev.tv Team
4.7 (26,924)
C# Intermediate: Classes, Interfaces and OOP
Mosh Hamedani
4.6 (23,227)
RPG Core Combat Creator: Learn Intermediate Unity C# Coding
Ben Tristem, Rick Davidson, Sam Pattuzzi, GameDev.tv Team
4.7 (8,519)
Complete C# Masterclass
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.5 (12,216)
Design Patterns in C# and .NET
Dmitri Nesteruk
4.4 (7,146)
Unity C# Scripting : Complete C# For Unity Game Development
Raja Biswas, Charger Games
4.4 (1,409)
RPG Inventory Systems: Intermediate C# Game Coding Course
Sam Pattuzzi, GameDev.tv Team, Rick Davidson
4.3 (399)

More C# Courses

C# 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 for Business.

Request a demo