Computer Applications
Write the values of r and s after the execution of the following code.
int p = 11, q = 21, r, s;
r = ++q;
s = p++;
r++;
Java Operators
2 Likes
Answer
After execution of the given code, r = 23 and s = 11.
Explanation
| Statement | Remarks |
|---|---|
| int p = 11, q = 21, r, s; | p = 11, q = 21, r and s are declared |
| r = ++q; | r = 22 (prefix operator first increments the value and then uses it) |
| s = p++; | s = 11 (postfix operator first uses the value and then increments it) |
| r++; | r = 23 (value of r is incremented by 1) |
Answered By
1 Like
Related Questions
Assertion (A) The return statement causes program control to transfer back to the caller of the method.
Reason (R) The return statement immediately terminates the method in which it is executed.- Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
- Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
- Assertion (A) is true and Reason (R) is false.
- Assertion (A) is false and Reason (R) is true
Correct statement to declare an integer array of 10 elements.
- int[ ] arr = new int[10];
- int arr;
- int arr (10);
- int ( ) arr = new int (10);
Observe the following code and find that how many times will the loop execute?
int sum = 0, score = 0; double t; do { score = score + 1; sum = sum + score; } while(score <= 3); t = sum / 3;Write the Java statement for the following mathematical expression