QUESTION 1: Correct Consider this code: “int v = 20; –v; cout << v++;". What value is printed, what value is v left with? A) 20 is printed, v ends up with 19 B) 19 is printed, v ends up with 20 C) 20 is printed, v ends up with 20 D) 19 is printed, v ends up with 19 E) cannot determine what is printed, v ends up with 20 QUESTION 2: Correct Consider this code: "int s = 20; int t = s++ + --s;". What are the values of s and t? A) s is 19 and t is 38 B) s is 20 and t is 39 C) s is 19 and t is 39 D) s is 20 and t is 38 E) s is 20 and t cannot be determined

LANGUAGE: C++

CHALLENGE:

QUESTION 1: Correct Consider this code: “int v = 20; –v; cout << v++;”. What value is printed, what value is v left with? A) 20 is printed, v ends up with 19 B) 19 is printed, v ends up with 20 C) 20 is printed, v ends up with 20 D) 19 is printed, v ends up with 19 E) cannot determine what is printed, v ends up with 20 QUESTION 2: Correct Consider this code: “int s = 20; int t = s++ + –s;”. What are the values of s and t? A) s is 19 and t is 38 B) s is 20 and t is 39 C) s is 19 and t is 39 D) s is 20 and t is 38 E) s is 20 and t cannot be determined

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

2 Comments

  1. Allison on January 31, 2015 at 8:41 am

    Ok this : Consider this code: “int v = 20; –v; cout << v++;". What value is printed, what value is v left with?

    I dont need the answer I dont get why — is before v and does it mean something different from v–

    • Matthew Maennche on January 31, 2015 at 9:31 am

      This is the difference between prefix and postfix operators.

      Both the prefix and postfix increment and decrement operators affect their operands. The key difference between them is the order in which the increment or decrement takes place in the evaluation of an expression. (For more information, see https://msdn.microsoft.com/en-us/library/dy3d35h8.aspx) In the prefix form, the increment or decrement takes place before the value is used in expression evaluation, so the value of the expression is different from the value of the operand. In the postfix form, the increment or decrement takes place after the value is used in expression evaluation, so the value of the expression is the same as the value of the operand.

Leave a Comment

You must be logged in to post a comment.