Unary Operator in C

What is Unary Operator in c ?

unary operators are used for produce a new value. This operator require only one operand.

Types of Unary operators:

  •  Unary minus(-)
  •  Increment (++)
  •  Decrement (–)
  •  NOT(!)
  •  Address operator(&)
  •  sizeof()

Unary Minus (-) :

It is a unary operator which is used for changing the sign of a variable.
A positive number turns into a negative number and a negative number turns into a positive.

Example :

int a = 10,b ;
b = -a ; // b is assigned with -10

Increment (++) :

An increment operator is used to increment a variable by 1. The increment can be done in two ways.

i. Pre Increment :

In this method, the value of the variable is increment before it is used
 General syntax: ++a ( a is an integer variable).