How this question answer 12? I think the answer should be 11. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How this question answer 12? I think the answer should be 11.

Int i; For(i=0; i<=6; i++) i+=5; Cout<<i;

26th Feb 2021, 8:46 PM
Cem köylüoğlu
Cem köylüoğlu - avatar
6 Answers
+ 4
Because i<=6 so firstly I=0 then I++ add 1 to 0 then I+= 5 add 5 to 1 then check i<=6 again it is 6<=6? Then add 1 again it is 6+1 then add 5 it is 7+5 ===> 12
26th Feb 2021, 8:59 PM
HBhZ_C
HBhZ_C - avatar
+ 3
Cem köylüoğlu Yes 7 is bigger than 6 but after satisfying condition of i <= 6 i will be incremented by 1 so i would be 7 but after 7 <= 6 will be false so loop will stop to iterate there and it will go outside the loop So finally i is 7 then 7 + 5 = 12
26th Feb 2021, 9:03 PM
A͢J
A͢J - avatar
+ 1
Cem köylüoğlu No answer should be 12 because of i <= 6 , i++ will increase i with 1 so i would be 7 No i = 7 + 5 = 12
26th Feb 2021, 8:55 PM
A͢J
A͢J - avatar
+ 1
Okey right now understood
26th Feb 2021, 9:02 PM
Cem köylüoğlu
Cem köylüoğlu - avatar
+ 1
Anthony Dwomoh Don't spam
26th Feb 2021, 9:13 PM
A͢J
A͢J - avatar
0
How 7 bigger then 6. ` 7<=6 `?
26th Feb 2021, 8:59 PM
Cem köylüoğlu
Cem köylüoğlu - avatar