A statement
is an instruction that is executed and typicallyupdates some variable (called a side effect).
An expression is something that is evaluated and does not update
a variable (typically)
int x,y;
y=5;
x = (y = y+2);
What is x going to be?
Evaluate 5+2 and store 7 in y
2 Above also resulted in evaluating the y=y+2 expression, to 7.
→ store 7 in x.
It is very bad Idia to do so
Assignment Statements
In an assignment statement, first the expression on the right-hand side of the equal sign is
evaluated and then the variable on the left-hand side of the equal sign is set equal to this value.
SYNTAX
Variable = Expression;
EXAMPLES
distance = rate * time;
count = count + 2;
No comments:
Post a Comment