#include
First, you need to understand that the do-while structure does the checking at the end of the loop, rather than at the beginning (different than both for and while structures). Second, whenever you do ++counter <= 10, first the program will add one and then it will check the statement <= 10 for a truth value. So, on the second to last pass, this is more or less what happens: counter = 10 from the previous loop. do -> printf("%d ", counter) will output 10, then it goes and ++counter, counter = 11 now, is 11 <= 10, no, so we quit and continue to the next step. If it's counter++, then counter <= 10 will be evaluated, will return true (10 = 10), and only then the ++ will be evaluated. So now, counter = 11, we enter the do statement again, that prints 11, and then quits (11 is not <= 10).
Try this... int i=1; 1- cout<<++i; cout<<i; 2- cout<<i++; cout<<i; You should understand from this the difference between prefix and postfix...
Join our real-time social learning platform and learn together with your friends!