sum = 42 - 12 ;
Yes, the statement is syntactically correct.
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:
For example, the assignment statement:
sum = 32 + 8 ;
asks for two actions:
32 + 8 is calculated, yielding 40.
40 is placed in sum
Note (May, 2002): I've just spent several hours grading student programs from second semester computer science. Several programs were not working because their authors forgot that these two steps happen one after the other. Without this concept, an easy program became difficult.
What does the following assignment statement statement do:
sum = 42 - 12 ;
(What are the two steps, in order?)