A good answer might be:

Yes.

Prefix Increment Operator

The increment operator ++ can be written in front of a variable. When it is written in front of a variable (as in ++counter) it is called a prefix operator; when it is written behind a variable (as in counter++) it is called a postfix operator. Both uses will increment the variable; However:

  • ++counter means increment before using.
  • counter++ means increment after using.

When the increment operator is used as part of an arithmetic expression you must distinguish between prefix and postfix operators.

int sum = 0;
int counter = 10;

sum = ++counter ;

System.out.println("sum: "+ sum " + counter: " + counter );
It is vital to carefully study the following:
  • The counter will be incremented before the value it holds is used.
  • In the example, the assignment statement will be executed in the usual two steps:
    1. Step 1: evaluate the expression on the right of the "=":
      • the value will be 11 (because counter is incremented before use.)
    2. Step 2: assign the value to the variable on the left of the "=":
      • sum will get 11.
  • The next statement will write out: sum: 11 counter: 11

Inspect the following code:

int x = 99;
int y = 10;

y = ++x ;

System.out.println("x: " + x + "  y: " + y );

QUESTION 6:

What will this fragment write out?

Click Here after you have answered the question