+ 2

Can Someone Pls. Explain Me The Output Of This Code.

Shouldn't The Outcome Be 1(Maybe?!?).Thanks For Answering. https://code.sololearn.com/cey92UK7Qx0c/?ref=app

24th Mar 2018, 7:46 AM
™TheChamp921
™TheChamp921 - avatar
7 Answers
+ 7
#include <iostream> using namespace std; int main() { int x=1; for(;x<6;x+=2) { x=x*x; } cout<<x; 1st loop=x=1//x=x*x=1//x=+2=3 2nd loop=x=3//x=x*x=9//x=+2=11 x<6 condition false loop end result 11
24th Mar 2018, 7:52 AM
Scooby
Scooby - avatar
+ 6
Ohh....Thanks SD....🙆
24th Mar 2018, 7:53 AM
™TheChamp921
™TheChamp921 - avatar
+ 5
no problem
24th Mar 2018, 7:54 AM
Scooby
Scooby - avatar
+ 4
But why it prints the x in the incrementation brackets and not that variable x of the for loop block
24th Mar 2018, 7:55 AM
™TheChamp921
™TheChamp921 - avatar
+ 4
in loop block there is no cout.. after calculate x value its print after loops end..
24th Mar 2018, 7:58 AM
Scooby
Scooby - avatar
+ 4
Again Thanks SD You Are Awesome And An Inspiration Too...Best Wishes😇😊
24th Mar 2018, 8:00 AM
™TheChamp921
™TheChamp921 - avatar
+ 3
it pleasure to me.. u too.. good luck
24th Mar 2018, 8:01 AM
Scooby
Scooby - avatar