int sum; sum = 42 - 12 ;
Yes, the statements are syntactically correct.
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:
For example:
total = 3 + 5;
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;
points
.What happens FIRST when the following statement executes?
value = 2*3 ;