C Programming Operators :
|
|
||||||||||||||||||
4.1
|
|||||||||||||||||||
4.2
|
In C
Programming , Unary operators are having higher priority than the other
operators. Unary Operators are executed before the execution of the other
operators. Increment and Decrement are the examples of the Unary operator in
C.
|
||||||||||||||||||
4.3
|
1. Increment operator is used to increment the
current value of variable by adding integer 1.
2. Increment operator can be applied to only
variables.
3. Increment operator is denoted by ++.
A. Pre Increment Operator
Pre-increment operator is used to increment the value of
variable before using in the expression. In the Pre-Increment value is first
incremented and then used inside the expression.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then
value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before
using it in a expression.
B.
Post Increment Operator
Post-increment operator is used to increment the value of
variable as soon as after executing expression completely in which post
increment is used. In the Post-Increment value is first used in a expression
and then incremented.
b = x++;
In this example suppose the value of variable ‘x’ is 5 then
value of variable ‘b’ will be 5 because old value of ‘x’ is used.
|
||||||||||||||||||
4.4
|
Decrement Operator : Pre-Decrement / Post-Decrement:
Same as above
We have seen increment operator in C Programming which
increments the value of the variable by 1. Similarly C Supports one more
unary operator i.e decrement operator which behaves like increment operator
but only difference is that it decreases the value of variable by 1.
|
||||||||||||||||||
4.5
|
|
||||||||||||||||||
4.6
|
Whenever we use if statement then we
can use relational operator which tells us the
result of the comparison, so if we want to compare more than one conditions
then we need to use logical operators. Suppose we need to execute certain
block of code if and only if two conditions are satisfied then we can use
Logical Operator in C Programming.
|
||||||||||||||||||
|
|
||||||||||||||||||
4.8
|
Conditional Operators [ ?: ] :
Ternary Operator Statement in C
1.
They are also called as Ternary Operator .
2. They also
called as ?: operator
3.
Ternary Operators takes on 3 Arguments
Syntax :
expression 1 ? expression 2 : expression 3
where
·
expression1 is Condition
·
expression2 is Statement Followed if Condition is True
·
expression2 is Statement Followed if Condition is False
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
No comments:
Post a Comment