Output :#include<stdio.h> #include<conio.h> void main() { int i=0,j=0; j = i++ + ++i; printf("%d\n",i); }
2Explain ?
j = i++ + ++i;
- Above Statement Contain in all 4 Operators , [ = , Post Increment , Pre Increment , + ]
- According to Precedence there Order is -
Operator | Precedense Rank |
Pre Increment | 1 |
Post Increment | 2 |
+ | 3 |
= | 4 |
- It is very interesting to know that , Which one gets executed first Pre-Increment , Post-Increment ? Refer Operator Associativity Unary Operator's associativity is from [ R->L] so PreIncrement Operation gets executed first
- Here Pre Increment Operation uses new Value o 'i' so [ i = 1 ].
- This 'i = 1' is used for Post Increment Operation which uses Old Value i.e [i = 1] .
- Both '1's are added and value 2 is assigned to 'j'.
0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email