First c++ exam. Practice questions part 2.

[content removed]
Last edited on by admin
12.
why does B work? ceil(2.4) = 3, 3 % 2 = 1 which doesn't == 3. So it has something to do with the first part of the OR. Can anyone explain why that is true?
It looks like you're not parsing the expression right. The expression is equivalent to isFull = (isFull || ceil(2.4) % 2 + 1 == 3).

13. In integer arithmetic, 1/2=0. Therefore, 1/2*2=0. Therefore, 1/2*2+3=3.

15. Yes. It's called "casting". It means to explicitly convert a value from one type to another.

22. The function doesn't return anything. You can't print the value of nothing.

Unnumbered:
It's always possible to directly test the truth of a basic type such as int. Saying if (a) is the same as saying if (a!=0). Thus, if (x++ && y++) is the same as saying if (x++!=0 && y++!=0). Since x and y start as zero, the true block is not executed. After the comparison, x and y have been incremented, so x+y=2.

36. Despite the indentation, the second printing line is not included inside the true block of the if statement, so it executes regardless of the value of the condition.
The Unnumbered one is actually making me angry, not only is the answer not 'A' but it's 'E'. With out declaring that you are using the std namespace both "cout" and "endl" are undefined, this program will not compile so the answer is quite literally Undefined.

I think helios covered the rest.
Last edited on
Topic archived. No new replies allowed.