Unary Operator in C Programming Language

Unary Operator in C Programming Language



Operator
Operator is a symbol which are used to perform particular operation. In java language these opeatrs are classified into following types.

1.Unary Operators
2.Binary Operators
3.Ternary Operators

Unary Operator
If any operation perform on single operand (Variable) is known as uanry operator.
These operators are classified into following types.

1.Unary Minus Operator(-)
2.Increment Operator(++)
3.Decrement Operator(--)

Unary Minus:
Unary minus means sign value or minus value
Example:
int x=10;
then -x=-10;

#include <stdio.h>
                                                                         
int main() {
    int x;
    printf("Enter x value");
    scanf("%d",&x);
    printf("The sign value is %d",-x);

    return 0;
}
                                            

Output:

Enter x value 24
The sign value is -24



Increment Operator:
Increment Operator is used to increment the one value to the current value. These are classified into following types.

1.PreIncrement operator
2.PostIncrement operator

PreIncrement Operator(++x):
PreIncrement oprator is used to increment the value first assign the value later.
Example:
int x=10;
then ++x=11;

Program

Post Increment Operator:
PostIncrement Operator(x++): In the post incrementation assign the value first increment the value later.
Example:
int x=10;
then x++=10;
Program


Decrement Operator:
Decrement Operator is used to decrement the one value to the current value. These are classified into following types.

1.PreDecrement operator
2.PostDecrement operator

PreDecrement Operator(--x):
PreDecrement oprator is used to Decrement the value first assign the value later.
Example:
int x=10;
then --x=9;
Program


Post Decrement Operator:
PostDecrement Operator(x--): In the post Decrement assign the value first decrement the value later.
Example:
int x=10;
then x--=10;
Program