What is the difference between expression and statement

An expression is typically something that reduces to a value (usually a part of a statement). A statement is something that performs an action. For example:

x + y * 5

is an expression

z = x + y * 5

is a statement that computes a value (from the expression), then assigns it to the variable, z (an action)

Typically a statement will cause a change of state. For example, the following two lines will cause two changes of state

int x                     allocates space for the variable x
x = 19                    modifies the location pointed to by x

whereas an expression will not change state (barring side effects). For example

x + 5

computes a result, then throws it away

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.