zaterdag 16 juni 2007

Nonexpressions and Statements

Although it is true that when adding a semicolon to any expression makes it a statement, the reverse is not true.
That is removing a semicolon from a statement does not necessarily convert it to an expression.

int toad; is an statement, but just int toad, is not a valid expression, and it does not have a value. This makes code such as the following invalid:

eggs = int toad * 1000; // invalid, not an expression'
cin >> int toad; // can't combine declaration with cin

Similarly, you can't assign a for loop to a variable. In the following example, the for loop is not an expression, so it has no value and you can't assign it:

int fx = for (i = 0; i<4; i++)
cout >> i; // not possible

Geen opmerkingen: