for(y=1;y<10;y++)
x=y;
printf(“%d\n”,x);
printf(%d\n”,y);
it gives the output 9,10. why?
for(y=1;y<10;y++)
x=y;
printf(“%d\n”,x);
printf(%d\n”,y);
it gives the output 9,10. why?
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
for loop execute 9 times here.
when y will be 9, the condition statement i.e. y<10 is true , so x=y i.e. x=9 will be executed, now compiler jumps to y++ increments y to 10, and checks the condition part where 10< 10 is false and for loop is not executed this time , for loop ends here.
now x=9 here and y=10.
with out curly bracket loop executed in single line so loop increment the value of y till 10 and x till 9 so it print 9 and 10 .