8

Possible Duplicate:
Expression Versus Statement

What does expression mean? Something that evaluates to something, returns a value?

How is it different from a statement. Can a statement contain an expression and vice versa?

Community
  • 1
  • 1
Suleman
  • 81
  • 1
  • 1
  • 2

2 Answers2

13

Expressions do "return" a value, though they may be cast to (void). Statements don't evaluate to anything and only have side effects.

E.g. ; is a statement by itself, evaluates to nothing, and has no side effects.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
8

An expression is a instruction to be executed that returns a value (even if it returns a void).

A statement is used to form the sequence of a program (e.g. if-then, while-do statements). A statement can be simple or complex and can contain 0 or more expression.

As @Frédéric Hamidi said, a ; is a valid statement.

Wiki on:

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228