OutputModerate2 marks
Write the value of n after execution: char ch = 'd'; int n = ch + 5;
Topic: char arithmetic
Previous-year question practice database
Answer
Exam answer
n = 105
Explanation
When a char takes part in arithmetic, Java promotes it to its ASCII value. 'd' is 100 (working from the anchor 'a' = 97: b = 98, c = 99, d = 100). So n = 100 + 5 = 105. Because n is declared int, the number itself is stored and printed. Had it been declared char, the value 105 would have been shown as the character 'i' instead — the same arithmetic, a different display. Fix the anchors: A = 65, a = 97, 0 = 48.
More from Revision Tour I
The full form of JVM is:2026Which of the following occupies 2 bytes of storage?2026In a statement c = c + (x * d + e); which variable is an accumulator?2026Assertion (A): The result of the Java expression 3 + 7/2 is 6.
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.2026Evaluate the Java expression:
x = a * b % (++c) + (++a) + (--b);
if a = 7, b = 8, c = 22026System.out.println('Z' + 32); will display:2025