Expressions and Statements
- Statements are the basic program steps of C and most of the statements are constructed from expressions.
- An expression is a combination of operators and operands
- Operands are the operators on which an operator operate on.
- It might be a constant, variable or a combination of two.
- Every expression has a value and return to a value.
- Example:
Minus is an actual argument in C which is a unary or a single argument operator. So, -9 is an example.
5+23 is an expression where there is an operator in between two constants.
a*(b + c/d)/20 is an expression in which we have many operators.
Now we have an expression q = 5*2 where we have assigned q is equal to 5 multiplied by 2 which is assuming a variable to be equal to two constants.
- Statements are building blocks of a program.
- A program is a series of statements which end with a semi-colon. (simple statement)
- A complete statement will compile the program.
- Declaration Statement: int V;
- Assignment Statement: V = 6;
- Function call statement: printf(“V”);
- Structure Statement: while (V < 20) V = V + 1;
- Return Statement: return 0;
- C considers any statement with a semi-colon in the end.
- So, -8 and 2+221 are valid statements.
- Compound Statements: Two or more statements coming together by enclosing them with braces.
int index = 0;
while (index < 10);
{
printf(“Hello”);
index = index +1;
return 0;
}