0

# Why does this ==20

#include<iostream> using namespace std; int main() { int x, y, z; y = z = 0; for (x=0; x<10; x++) { y = y + 1; } z = x + y + z; cout << z; }

2 Answers

+ 3

Y0gurt because you have both x & y adding 1 each cycle
x++ is incrementing
and y = y + 1 is doing the same thing
so when x is 9 it increments one last time to 10 and y = 10 so x + y = 20 + z which is 0 as it was not used in the loop itself. So when z was finally used it was 20

+ 1

BroFar BroFar thank you so much! that helps alot :)