So this post will be about prefix
In prefix increment the value is incremented just when it is processed lets take an example to understand
e.g.
A=9, B;
B=++A;
here B will be assigned the value of A after the value of is incremented which is 10. So A will have now value 10.
Another e.g. to understand well
C=99, D;
D=++C;
++D
Now have a go in this. Think of what the answer could be.
Got It.
Here is the solution. In this C is initialized a value 99 while D is just initialized. In the second line D is assigned the value of C after the increment which will be now 100. and So C will also have value of 100. And on the third line D is incremented so D will be 101 now.
For decrement it is the same but the value decreases not increases.
Prefix increment/decrement save time also.
Good luck with learning.
Happy learning.
No comments:
Post a Comment