void main()
{
int i=5;
printf("%d",i++ + ++i);
}
output: 12
Explanation: all functions pass the value from right to left therefore i++ + ++i in this sequence first of all solve the ++i and then solve the i++ first increment by one i.e. 6 and then it solve i++ i.e. 5
printf("%d",i++ + ++i);
printf("%d",i++ + 6); // here i++ is 6 because i is assigned 6.
printf("%d",6 + 6); // after this operation again i will be incremented and becomes 7.
printf("%d",12);
add an extra line printf("%d",i); to check the value of i. it is 7.
if it is ("%d", ++i + ++i);
then output will be 13.
{
int i=5;
printf("%d",i++ + ++i);
}
output: 12
Explanation: all functions pass the value from right to left therefore i++ + ++i in this sequence first of all solve the ++i and then solve the i++ first increment by one i.e. 6 and then it solve i++ i.e. 5
printf("%d",i++ + ++i);
printf("%d",i++ + 6); // here i++ is 6 because i is assigned 6.
printf("%d",6 + 6); // after this operation again i will be incremented and becomes 7.
printf("%d",12);
add an extra line printf("%d",i); to check the value of i. it is 7.
if it is ("%d", ++i + ++i);
then output will be 13.
No comments:
Post a Comment