- 1

I wonder why the output is 12?

#include <iostream> using namespace std; int main(int argc, char *argv[]) { int f = 1, i = 2; while (++i < 5) { f *= i; } cout << f; return 0; } 1st interaction ++i < 5 so 3<5 f= 1*3 2nd 4<5 f= 4*3 So the output is 12, am I get it right?

5th Mar 2020, 2:39 AM
Sh.A.kH.
Sh.A.kH. - avatar
4 ответов
+ 7
You are right. If you run the code you'll see 12 as output. Everything is ok. Another doubt or that's it?
5th Mar 2020, 2:55 AM
Kevin ★
+ 5
Tip: use the console in edge situations in order to understand what's going on under the hood. https://code.sololearn.com/cemdd0byk70K/?ref=app
5th Mar 2020, 3:12 AM
Kevin ★
+ 4
Do not post anymore "I wonder why the output is so and so" and answer yourself. This kind of stuff will best suit your feed. Only ask questions that need to be answered. https://www.sololearn.com/discuss/1316935/?ref=app https://www.sololearn.com/discuss/2189994/?ref=app https://www.sololearn.com/discuss/2190004/?ref=app
5th Mar 2020, 3:45 AM
Avinesh
Avinesh - avatar
+ 2
Sorry, no problem! I get it!
5th Mar 2020, 3:50 AM
Sh.A.kH.
Sh.A.kH. - avatar