The C++ intro class of doom!

Some men just want to watch the world burn. Some of them are teacher assistants. And some of them give tests like this to an intro class. Sure, it’s not very difficult (except for 1e, which requires deeper understanding of the language), but it’s really, really tricky.
Well, check for yourself.

Easily findable link: [link] [link]

Warning: spoilers ahead.

1) a,c
1b is equal to x++ + 3, so it’s correct
1c there’s no operator>> for std::ostream
1e is syntactically correct, but it is undefined behaviour.

2)a. 2
2)b. -10
2)c. 4
2)d. 5
2)e. true

5) “This is the answer.”
The tricky part is noticing that operator= instead of operator== is used, so (with y=3) x=y changes the value of x to 3 and evaluates to 3 as well.

Bonus: “jk” (it prints characters, not variables). The loops are a red herring.

2 thoughts on “The C++ intro class of doom!

    1. Good catch, it was a typo on my part ;)

      I assume that no further comment is necessary.

Leave a Reply

Your email address will not be published.