sir, I have some problem in Pre-increment operator for the following expression.
i=10;
printf(“%d\n”,++i + ++i + ++i);
I am getting un-expected output. it’s answer is 37.. but how??
sir, I have some problem in Pre-increment operator for the following expression.
i=10;
printf(“%d\n”,++i + ++i + ++i);
I am getting un-expected output. it’s answer is 37.. but how??
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
Hey manoj…
I think what is going here is that…… the statement will be start executing from right and it take first i then preincrement it, then it find an addition operator so it goes to next i , here it finds another preincrement so now value of i is 12 and now the rightmost 2 ++i get added so result here is 24 and value of i=12…
now there is another addition so it goes to next i, and again preincrement so i=13 and 13+24=37
Hope I am right, yet see what other person say about it
Hey manoj…
I think what is going here is that…… the statement will be start executing from right and it take first i then preincrement it, then it find an addition operator so it goes to next i , here it finds another preincrement so now value of i is 12 and now the rightmost 2 ++i get added so result here is 24 and value of i=12…
now there is another addition so it goes to next i, and again preincrement so i=13 and 13+24=37
Hope I am right, yet see what other person say about it
I have got the answer… it will be solved like
((++i + ++i ) + ++i)…
but thanx 4 reply…