Expression
Definition: Expression smallest unit of computation.When variables/constants are used with operators they form expression. Each expression is evaluated to value which is called value of expression.
For Example
- a + 5 + b -> It is expression that glues variable a and b constant 5 with addition operator.
- 4 ^ 3 + 2 -> It is expression that glues constants 4 3 and 2 with XOR and addition operator.
NOTE that there is no semicolon needed at the end of expression.
In 2nd example is 4 ^ 3 done first ? or 3 + 2 is done first ? To know this we need to know Precedence of operator. Precedence of operator tells priority of operators. This will be taken in next article.
Statement
Definition: Statement is smallest independent unit in C Program.For example
a = b + 2;
Above C code is a statement. It is statement that contains expression b + 2 and also result assigned to a. Generally statement ends with semicolon, while expression do not.
Expressions are like idioms and phrases while statement are like sentences. These two words will be used a lot going forward.
Links
Quiz - Not Yet written !!Next Article - C Programming #16: Operator precedence, associativity and order of evaluation
Previous Article - C Programming #14: Operators - Comma
All Article - C Programming
No comments :
Post a Comment