I wonder why the output is 21? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I wonder why the output is 21?

#include <iostream> using namespace std; int main(int argc, char *argv[]) { int a=1; for (int i=0; i<20; i++) { a++; } cout << a; return 0; }

5th Mar 2020, 2:01 AM
Sh.A.kH.
Sh.A.kH. - avatar
2 Answers
+ 2
1st interaction i=0 0<20 so a=2 Then i=1 a=3 i=2 a=4 i=3 a=5 i=4 a=6 i=5 a=7 i=6 a=8 ~~~~~ i=19 a=21 Am I right?
5th Mar 2020, 2:05 AM
Sh.A.kH.
Sh.A.kH. - avatar
+ 2
Thank you Jamie🌷
5th Mar 2020, 2:08 AM
Sh.A.kH.
Sh.A.kH. - avatar