#include
int main()
{
int i=1;
printf(“%d%d%d%d%d”,i,++i,i++,++i,++i);
return 0;
}
what wil be the output with reason?
#include
int main()
{
int i=1;
printf(“%d%d%d%d%d”,i,++i,i++,++i,++i);
return 0;
}
what wil be the output with reason?
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
the output should be 5 5 5 5 5
but i know it will be incorrect for one of the operators for sure
no arjumand this is wrong output.
the actual output is 55355 and the reason is in heamnt’s comment….
your output should be 5 5 3 5 5
1st step: your execution will start from right to left.
2nd step:remember this point when you use PRE INCREEMENT operator i.e (++i) ,it takes the last updated value of i
for example..
let i=1;
printf(“%d %d %d %d \n”,++i,++i,++i,++i);
your output would be 5 5 5 5
because the last updated value in i is 5;
and in your case
i=1;
prntf(“%d %d %d %d %d\n”,i,++i,i++,++i,++i)
taking from the right side
2
3
3
5
5(last updated value is 5)
so wherever you have declared the ++i operator replace it with 5 but in case of post increement operator (i++)it would be 3
thanx for the help hemant i also conclude this reason for the problem…….