go to previous page   go to home page   go to next page hear noise highlighting
int sum;

sum = 42 - 12 ;

Answer:

Yes, the statements are syntactically correct.


Assignment Statement Semantics

The syntax of a programming language says what programs look like. It is the grammar of how to arrange the symbols. The semantics of a programming language says what the program does as it executes. It says what the symbols mean. This page explains the semantics of the assignment statement.

An assignment statement does its work in two steps:

  1. First, do the calculation on the RIGHT of the equal sign.
    • If there is nothing to calculate, use the value on the right.
  2. Next, replace the contents of the variable on the LEFT of the equal sign with the result of the calculation.

For example:

total = 3 + 5;
  1. Do the calculation 3+5 to get 8.
  2. Put 8 in the variable named total.

It does not matter if total already has a number in it. Step 2 will replace whatever is already in total .

For example:

points = 23;
  1. Use the value 23.
  2. Put 23 in the variable named points.

QUESTION 12:

What happens FIRST when the following statement executes?

value = 2*3 ;

go to previous page   go to home page   go to next page