What is the output of the following code?
public class Main { public static void main(String[] args) { int a = 10; long b = 20; short c = 30; System.out.println(++a + b++ * c); } }
A
The prefix increment operator ++ used with the variable a will increment its value before it is used in the expression ++a + b++ * c.
The postfix increment operator ++ used with the variable b will increment its value after its initial value is used in the expression ++a + b++ * c.
Therefore, the expression ++a + b++ * c, evaluates with the following values:
11 + 20 * 30
public class Main { public static void main(String[] args) { int a = 10; long b = 20; short c = 30; System.out.println(++a + b++ * c); } }
The code above generates the following result.