I was studying for an exam and came across two questions that me and my friends didn't know the answer to. We are given the answer but we just can't figure out what the answer is what it is.
First, why does this code give an error?
int z=5, q=2; cout << 10/(q/z) << endl;
Second, what does this code equal? I believe it equals 19 but our teacher says it is 20.
//Given x=10 and y=5 y = 2*y++ + --x; cout << y << endl;
Wouldn't y = 2*y++ + --x just be the same as 2*5 + 9 because y++ is post-processing which means that after this line is run y is now equal to 6 and not 5? And --x is equal to 9 because it is pre-processing so 10 would be decremented to 9 before the math?