+ 1

how is the output 12345678910

int i = 10; while(i--) cout << 10 - i;

9th Jan 2020, 7:15 AM
Ariz imam
Ariz imam - avatar
4 Réponses
+ 5
As in your while loop it specifies that while(i--) it means that it will first evaluate th value of 'i' and then decrement it That's why you are getting ths output At first itteration value that is evaluated is 10 and after that it has been decreased to 9 Similarly at last the value to be evaluated is 1 and after that it is decreased to 0
9th Jan 2020, 7:30 AM
Arsenic
Arsenic - avatar
+ 3
Ariz imam that's because you are printing '10-i' not 'i'
9th Jan 2020, 7:37 AM
Arsenic
Arsenic - avatar
+ 1
Arsenic ok mate..
9th Jan 2020, 1:07 PM
Ariz imam
Ariz imam - avatar
0
why the thread of output is in reverse.. it should be 10987654321
9th Jan 2020, 7:36 AM
Ariz imam
Ariz imam - avatar