Operators in C Language?

by Emma

Operators in C Language

  1. An operator is a symbol that operates Value or Variable. For example: + is an operator that adds numbers. C programming consists of many built-in operators.
  2. Operators work together with one or more variables, constants or operands. Variable, constant, operands, function and operators merge all these together to form an expression.
  3. Expression is made by combining operands and operators. Operands are variables that together with operators perform certain operations.

Types of Operators in C

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary or Conditional Operators
  • Assignment Operator
  • Special Operator
Type of Operator Symbolic representation
Arithmetic operators +, -, *, /, %
Relational operators >, <, ==, >=, <=, !=
Logical operators &&, ||, !=
Increment and decrement operator ++ and —
Assignment operator =
Bitwise operator &, |, ^, >>, <<, ~
Comma operator ,
Conditional operator ?:

Arithmetic operators

Arithmetic operators are used to perform mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/) and modulus (%).

Operator Description
+ This operator is used to connect two operands.
This operator is used to subtract two operands.
* This operator is used to multiply two operands.
/ This operator is used to divide two operands.
% This operator is used to partition the modulus of two operands.

Increment and Decrement Operator

Both the Increment and Decrement operators are very useful operators commonly used to reduce calculations, ie ++ x and x ++ means x = x + 1 i.e. increasing the value 1 in X and – x and x– means x = x – 1 ie subtracting 1 value in x. But there is little difference between ++ or −− written before or after the operand. The pre-increment first adds 1 to the operand and then the result is assigned to the variable on the left, while the post-increment first assigns a value to the variable on the left and then adds 1 to the operand.

Operator Description
++ Increment operator – Increases integer values ​​one by one.
−− Decrement operator – Decreases integer values ​​one after another

 Relational operators

Relational operators are used to compare two values. Hence it is also called Comparison operator.

Operator Description
== This operator is called equal to operator. This operator is used to equal check two values. If both values ​​are equal then it returns true.
!= This operator is called Not equal to operator. It is used to check that two operands are not equal. Meaning this operator is used to check the value of two operands, if both operands do
not have equal value then it returns true.
> This operator is called Greater than operator. It is used to check the value of the first operand more than the value of the second operand. If the value of the first operand is greater than the value of the second operand then it
returns true like (5> 2) return true
< This operator is called Less than operator. It is used to check the value of the first operand less than the value of the second operand.
If the value of the first operand is smaller than the value of the second operand then it
returns true such as (3 <4) return true
>= This operator is called Greater than equal to operator. It is used to check the value of the first operand greater than and equal to the value of the second operand. If the value of the first operand is greater than or equal to the value of the second operand then it returns true as (5> = 5) return true
<= This operator is called Less than equal to operator. It is used to check the value of the first operand less than the value of the second operand. If the value of the first operand is smaller than or equal to the value of the second operand then it returns true as (5 <= 5) return true

Logical Operators

There are three types of Logical Operator in C, when we have to choose one of the two conditions, then we use Logical Operator. && – and, || – or,! – Not.

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

Bitwise Operator

In C language the bitwise operator is used to perform bit level operations.

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

 Special Operators

C supports some special operators.

Operator Description
sizeof() This operator returns the size of any variable according to its data type.
& This returns the address of the operator variable.
* The pointer variable is used to denote.

Related Posts

Leave a Comment