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

Language

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary or Conditional Operators
  • Assignment Operator
  • Special Operator
Type of OperatorSymbolic 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 (%).

OperatorDescription
+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 operand.

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

 Relational operators

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

OperatorDescription
==This operator is called equal to operator. This operator is used to similar 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 the operator. It is used to check the first operand’s value more than the second operand’s value. 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 a Less than the 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 accurate 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 similar 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 accurately 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 accurately 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, we use Logical Operators. && – and, || – or,! – Not.

OperatorDescriptionExample
&&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.

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

 Special Operators

C supports some special operators.

OperatorDescription
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