+ 4

Quiz Rejected

//code contains out of scope syntax What is the output of this code? int i=0; int x=10; for (;i <x;i++,x--); cout <<x+i; can anyone please explain in detail what is wrong in it ?

24th Mar 2017, 11:18 AM
Sahaj Bamba
Sahaj Bamba - avatar
9 odpowiedzi
+ 17
This is probably due to the confusing statements in for loop syntax. The alternative which i suggest: while (i < x) { i++; x--; } cout << i+x;
24th Mar 2017, 12:14 PM
Hatsy Rei
Hatsy Rei - avatar
+ 16
*shrugs* Add more cookies to your codes? 🍪
24th Mar 2017, 1:02 PM
Hatsy Rei
Hatsy Rei - avatar
+ 8
u r terminating the for loop with a semicolon lol😂
24th Mar 2017, 4:12 PM
Ronit Kumar
Ronit Kumar - avatar
+ 4
isn't confusing code is what challenges us to think and quizes are meant for that else it is just a matter of speedy maths .
24th Mar 2017, 12:43 PM
Sahaj Bamba
Sahaj Bamba - avatar
+ 2
i did that on purpose to make it challenging . its answer is just 10
24th Mar 2017, 2:25 PM
Sahaj Bamba
Sahaj Bamba - avatar
+ 1
COOKIES ?? I didn't get that . Is that some kind of technical joke ?
25th Mar 2017, 9:24 AM
Sahaj Bamba
Sahaj Bamba - avatar
0
come to think of it, the question is correct because it has a correct answer = 10.
24th Mar 2017, 2:42 PM
CIVM
- 1
/* for (;i <x;i++,x--); don't terminate the for loop with semicolon(;) */ int i=0; int x=10; for (;i<x;i++,x--) cout <<x+i;
24th Mar 2017, 2:23 PM
CIVM
- 1
There is an error, you had put semicolon in the begging of the for statement, and you have a semicolon at the end of the for statement, after the bracket.
25th Mar 2017, 7:52 AM
LifeHacks Trending
LifeHacks Trending - avatar