Expression

An Expression is a line of code that evaluates to a value.

 

e.g.    a = b* c

 

All expressions have a type and a result.

 

An expression (e.g. a = b * c ) becomes a statement when followed by a semi-colon (i.e. a = b * c ; )

 

So, basically, an expression is the computational section of the code.

 

C++ definition: "a sequence of operators and operands that specifies a computation".

 

#include <iostream>

using namespace std ;

int main () {

	int a, b, c ;	//statement

	a = 5, b = 6 / 2, c = a + b ;  //3 comma separated expressions, within a statement

	cout << "c = " << c << endl ;	//statement

	return 0;
}

 

The 3 comma separated expressions on line 9 could have been separated on to individual lines, creating 3 statements.

Leave a Reply