Auto Decrementatin
Operator (- - )
Post Decrement Mode:
The value of the
variable is assigned first.
Then the
decrementation follows.
Illustration :
x = y--
Step 1 : The original
Value of y is assigned to x First.
Step 2 : Then the
Value of y is decremented by 1.
Illustrative Program
Program
#include
<stdio.h>
void main()
{
int y = 6;
printf(“y = %d”,
y--);
}
Pre Decrement Mode:
The value of the
variable is decremented first.
Then the assignment
follows.
Illustration :
x = --y;
Step 1 : Value of the
y is decremented by 1 First.
Step 2 : Then the
assignment to x is done.
Illustrative Program
Program
# include
<stdio.h>
void main()
{
int y = 6;
printf (“y = %d “, -
-y);
}
Things to note:
a++ : The result of
the expression is the original value of a.
Here the original
value of the y is
assigned to the
printf first and then
the value of y is
decremented by 1.
Here the original
value of the y is
decremented first and
then the value
of y is assigned to
printf.
++a : The Result of
the expression is incremented value of a.
a-- : The result of
the expression is the original value of a.
--a : The Result of
the expression is decremented value of a.
The Types of Combinations
for Auto Incrementation and
Decrementation
Operators.
The process of these
incrementation and decrementation operators in real time
can appear in four
major combinations, depending upon these combinations only the compiler takes
the priority of the execution or operation and assignment. These concepts also
depend upon the standards of the nature of the compiler, whether it is a STACK
oriented or QUEUE Oriented in Nature. But major C or C++ compilers are STACK
oriented, hence all these four combinations generally are acceptable.
Type I: Sequetial
Execution Process Logic.
Illustrative Program
Program
# include
<stdio.h>
void main()
{
int x=5;
printf(“value of x =
%d”, x++);
printf(“value of x =
%d”, - -x);
printf(“value of x =
%d”, x - -);
printf(“value of x =
%d”, ++x);
printf(“value of x =
%d”, x++);
}
Type II: Multiple
Operation Single printf() Integration Logic.
Illustrative Program
Program
# include
<stdio.h>
void main ()
{
int x=6;
printf(“%d %d %d”,
x++, ++x, x--);
}
Solving Procedure:
Evaluation starts
from the RIGHT MOST EXPRESSION.
PUSH the RESULT of
the EXPRESSION onto a STACK.
Use the NEW VALUES of
‘x’ to find the result of the NEXT EXPRESSION.
STACK:
→It is a set of
elements where INSERTION and DELETION is performed at one end.
→INSERTION of VALUES
into STACK is termed as PUSHING.
→DELETION of VALUES
from STACK is termed as POPPING
→The TRANSACTION
follows “Last In First Out” (LIFO)
principle.
TYPE III: Expression
Oriented Explicit Assignment Logic.
Illustrative Program
Program
# include
<stdio.h>
void main()
{
int i, j = 4;
i = j++ * ++j * j--;
printf (“\n i = %d, j
= %d”, i, j);
}
Solving Procedure:
Check all the Prefix
Expressions that are applied in the Expression.
Substitute the Final
Value to of the previous step to every expression.
Calculate the Result
of the Actual Expression.
Then Check the
Postfix Expressions to Finalize the Value.
TYPE IV: Expression
Oriented Implicit Assignment Logic.
Illustrative Program
Program
# include
<stdio.h>
void main ()
{
int x = 4;
printf(“%d”, x++ *
++x * x--);
}
Solving Procedure:
Start from Left most
expression and execute each and every expression.
Stack
Pushing
Popping
No comments:
Post a Comment