+ 2
I have 3 question about C++(continue)
int x=1; if(x>0) { x=2; cout<<++x; } cout<<x; The answer is 31. But I think it must be 32, can you explain? Thanks for answers.
5 Answers
+ 8
In reply to OP:
The answer should be 33 unless you missed some syntax.
int x=1;
if(x>0) // true
{
x=2; // x becomes 2
cout<<++x; // 2 incremented to 3, prints 3
}
cout<<x; // prints 3.
+ 8
@Joseph Perhaps it was because you posted three seperate threads with similar titles causing some people to believe some were duplicates. Don't mind the downvotes.
+ 7
@Joseph Hardrock Just report anything you consider suspicious. They will be reviewed and evaluated. Nothing will go wrong.
+ 2
I posted three separate threads, because they are not squeezing in a 1 post.
+ 2
But the Sololearn is saying that the answer is 31.
And are we counting the increments in cout? Because in some situations for example in return we are not counting the increments or decrements. I guess some incrementing process doesn't affect original memory of value. What are you thinking about this?By the way, should I report this question to SoloLearn? Thank you.