+ 1

Why answer is 8 ?😅

#include <iostream> using namespace std; int main() { int x=4,y,z; y=--x; z=x--; cout<<x+y+z; }

4th Dec 2020, 6:50 AM
Sarthak
Sarthak - avatar
7 Answers
4th Dec 2020, 7:25 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 3
Are you sure? cout << y << z << x; Will output all three variables <y>, <z> and <x>. Did you mean something like this? cout << (y + z + x); This way it makes sense ...
4th Dec 2020, 7:04 AM
Ipang
+ 2
y = --x decrease and then assign z = x-- assign and then decrease
5th Dec 2020, 11:57 PM
Felipe Navarro TĂĄrraga
Felipe Navarro TĂĄrraga - avatar
+ 1
while printing the values of x,y,z y=3 z=3 x=2 is the output and i dont know why 😅
4th Dec 2020, 7:22 AM
Sarthak
Sarthak - avatar
+ 1
Is this one from challenges? If the snippet shown was exactly like that, and it says answer was 8, then the challenge is faulty.
4th Dec 2020, 7:25 AM
Ipang
+ 1
Capture the screen bro! if the snippet was exactly like that, and it says answer is 8, then the challenge is faulty, and it is worth to be reported. Some learners will be confused and mislead by that mistake, SoloLearn needs to know about this so they can do something about it.
4th Dec 2020, 7:34 AM
Ipang
+ 1
oh okie ...will report that
4th Dec 2020, 7:36 AM
Sarthak
Sarthak - avatar