Operators in C Language

Do you want to know all about operators in C language? Well, in this section of C programming you will learn all the types of operators and it’s functionalities.

Operators in C Language

C language provides a diverse set of embedded operators. An operator is a symbol asking the compiler to implement any mathematical or logical manipulation. Operators are used for manipulating data and variables within programs.

Types of Operators in C Language

C operators can be divided into the following types:

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators
  • Assignment operators
  • Conditional operators
  • Special operators

Let’s have a look at each of this one by one.

Arithmetic operators

It is used for operations like Addition, Subtraction, Multiplication, division, and modulus are done using arithmetic operators.
The symbol used for Arithmetic Operators in C programming language is “+”.

Operator Description
+ adds two operands
subtract second operands from first
* multiply two operand
/ divide numerator by denominator
% remainder of division
++ Increment operator – increases integer value by one
Decrement operator – decreases integer value by one

Example:

int sum=a+b;

printf("%d",sum);

Assignment operators

It is used to assign values of the variables.
The symbol used for Assignment Operators in C programming language is =, +=, -=, *=, etc.

Example:

int a=5;
int b;
b=a;//assigning value of b to a;

Relational operators

It is used for comparison of the value of two variables.
The symbol used for Relational operators in C programming language is ==, != , >, <, >= & <=.

Operator Description
== Check if two operand are equal
!= Check if two operand are not equal.
> Check if operand on the left is greater than operand on the right
< Check operand on the left is smaller than right operand
>= check left operand is greater than or equal to right operand
<= Check if operand on left is smaller than or equal to right operand

Example:

if(a>5)
{
return 1;

Logical operators

It is used to control program flow.

Operator Description Example
&& Logical AND (a && b) is false
|| Logical OR (a || b) is true
! Logical NOT (!a) is false

Bitwise operators

Used to do bit operations on two variables. The symbol used for Bitwise operators in C programming language is &, |, ^, ~, >> and <<.

Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< left shift
>> right shift

Conditional operators (ternary operators)

It is used to execute the first statement if the condition is true and executes another statement if the condition is false.

Increment/decrement operators

It is used to increment or decrement the value of a variable.

Special operators

There are some special operators in C programming Language like &, *, sizeof( ), and ternary operators.

The syntax of a conditional operator is :

expression 1 ? expression 2: expression 3

Special operator

Operator Description Example
sizeof Returns the size of an variable sizeof(x) return size of the variable x
& Returns the address of an variable &x ; return address of the variable x
* Pointer to a variable *x ; will be pointer to a variable x