int sum; sum = 42 - 12 ;
Answer:
Yes, the statements are syntactically correct.
Assignment Statement Symantics
The syntax of a programming language says what programs look like. It is the grammar of how to arrange the symbols. The symantics of a programming language says what the program does as it executes. It says what the symbols mean.
This page explains the symantics of the assignment statement. An assignment statement asks for the computer to perform two steps, in order:
An assignment statement does its work in two steps:
- First, it does the calculation on the RIGHT of the equal sign.
- This means it calculates the value of the expression on the right.
- If there is nothing to calculate, it just uses the value that is there.
- Next, it replaces the contents of the variable to the LEFT of the equal sign with the result of the calculation.
For example:
total = 3 + 5;
- Does the calculation 3+5 and gets 8.
- Then puts the 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 .
QUESTION 12:
What happens FIRST when the following statement executes?
value = 2*3 ;