What is the result? Given the code fragment: What is the result? Given the code fragment: What is the result? A. 3 3 B. 3 2 C. 1 2 D. 2 2 Explanation: Show Hint ← Previous question Next question →
imyrta Answer: D Explanation: Operations used in this case are 1. postfix(expr++ expr–) 2. unary(++expr –expr) The postfix Operation Firstly assigns a value and after that applies the operation The unary Operation Firstly applies the operation and after assigns the value. Example // Increment operators x = 1; y = ++x; // x is now 2, y is also 2 y = x++; // x is now 3, y is 2 // Decrement operators x = 3; y = x–; // x is now 2, y is 3 y = –x; // x is now 1, y is also 1 Reply
D
D
Answer: D
Explanation:
Operations used in this case are
1. postfix(expr++ expr–)
2. unary(++expr –expr)
The postfix Operation
Firstly assigns a value and after that applies the operation
The unary Operation
Firstly applies the operation and after assigns the value.
Example
// Increment operators
x = 1;
y = ++x; // x is now 2, y is also 2
y = x++; // x is now 3, y is 2
// Decrement operators
x = 3;
y = x–; // x is now 2, y is 3
y = –x; // x is now 1, y is also 1