Key Points :
Operators :
"Operators
are the special symbols which are used to perform operations.
The
symbols which are used to perform arithmetic, logical, relational, etc
operations
are
known as Operators."
Ex + , - , / , %
etc are operators.
Let us
know some general terms:
Ex. 20
+ 40
In
the example above the numbers 20 & 40 are known as operands.
The
'+' symbol is known as operator.
Types
of operators :
1]
Unary operators
2]
Binary operators
3]
Ternary operators
1]
Unary operators :-
"The
operator which needs only one operand to perform the operation is known as
Unary
operators."
Ex.
a++;
In
the above statement 'a' is a variable.
'++'
is an operator.
Unary
operator is of 2 types :
a)
Increment operator (++)
b)
Decrement operator (--)
a)
Increment operator
As
in name, the increment operator is used for increment the value.
Increment Operator is also divided in 2 types:
1) Prefix Increment operator (++a)
2) Postfix Increment operator (a++)
1) Prefix Increment operator
In Prefix Increment operator the value of the operator is incremented at the start.
Syntax : ++variable_name
Ex. int i = 5,j = 0;
j = ++i;
printf("j = %d",j);
Output: j = 6;
2) Postfix Increment operator
In Postfix Increment operator the value of the operator is incremented at the last.
Syntax : variable_name++
Ex. int i = 5,j = 0;
j = i++;
printf("j = %d",j);
Output: j = 5;
b) Decrement operator
As in name, the Decrement operator is used for Decrement the value.
Decrement Operator is also divided in 2 types:
1) Prefix Decrement operator (--a)
2) Postfix Decrement operator (a--)
1) Prefix Decrement operator
In Prefix Decrement operator the value of the operator is Decremented at the start.
Syntax : --variable_name
Ex. int i = 5,j = 0;
j = --i;
printf("j = %d",j);
Output: j = 4;
2) Postfix Decrement operator
In Postfix Decrement operator the value of the operator is Decremented at the last.
Syntax : variable_name--
Ex. int i = 5,j = 0;
j = i--;
printf("j = %d",j);
Output: j = 5;
No comments:
Post a Comment