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

2
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:



Q1- B)  19 is printed, v ends up with 20      
Q2-E)  s is 20 and t cannot be determined

2 comments

  • Allison says:

    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–

    • 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.

Add comment