+ 1

can any one explain how the out put comes for this code:

Sorry for not posting full code this is full code : #include <iostream> using names pace std; int main (){ int i=0; while(i++<5){ int j=i; while(j<3) cout<

23rd Dec 2016, 5:15 PM
Leoulg
Leoulg - avatar
2 Answers
+ 3
This code don't output anything else than a compilation error, because of the missing semi-colon at firstline... even if you encapsulte it in a main() fonction ( for make the code valid ). After correction ( not evident with no indentation, and curly brakets not always present: it's valid, but not evident if the missing is wanted or not ), the output is: 1 2 2 Correct ? Anyway, the "difficulty" here is in how works incrementation between post and pre ( i++ and ++j ). Well, it's just logical: i++ --> value of i is used before i modified ( reading direction: first i, second incrementation ) ++j --> value of j modified before j used ( reading direction: first incrementation, second j ) So, in your code, i is tested before incrementation, and j is tested after incrementation...
23rd Dec 2016, 6:26 PM
visph
visph - avatar
+ 1
can u post the complete code pls?
23rd Dec 2016, 5:27 PM
Leon Duric