Variable = ExpressionWe know what a variable is, i.e. somewhere to store the value of the expression, but just what is an expression? It's a statement that resolves to a value: either numeric or character.
What Exactly is a Statement?
A statement is a building block of a program. For example the assignment statementint a=10;This is also an expression and has the value 10. If we write this code
int b= (a=10) ;Both a and b will be set to the value 10.
In a later lesson we'll meet other statements such as if or while. Both of these require a conditional expression.
Conditional Expression
A conditional expression is one which evaluates as true (a non zero value) or false (0). True is almost always 1 but any non zero value is also true! A zero value is false, anything else is true.#include <iostream>Compile and run the example above. It should print out the following.
using namespace std;
int main()
{
int a=10;
int b=( a = 10) ;
int c=( a==10) ;
cout << "Value of b is " << b << endl ;
cout << "Value of c is " << c << endl ;
return 0;
}
Value of b is 10On the next page : Learn about the preprocessor.
Value of c is 1

