Expressions

An Expression is comprised of one or more operations. The objects of the operation(s) is reffered to as operands. the conditions are represented by operators.

A C++ expression is a combination of operations, constants, and variables.

An expression is any statement which is composed of one or more operands and returns a value. It may be a combination of operators, variables and constants. the expression may be simple or complex.

Rules of formationof expression

1) A signed constant, unsigned constant or a variable is considered as an expression.

2) An expression connected by an opeartor to a varible or constant forms an expression.

3) Two expression connected by an operator also forman expression.

4) Two oberators should not occur in continuation.

5) Literals, names and names qualified by the scope resolution operator : are called primary expressions

Types of Expression

1) Arithmetic Expression

An arithmetic expression can either be a constant expression, integer or real expression. It can also be a mixed expression. There can be Integer expressions and Real expressions.

2) Logical Expression

Logical expressions are those expressions which result in true (1) or False(0). these expressions return a 0 or 1 value.

Order of evaluation of expression

A number of logical and relational expressions can be linked together with the help of logical operators.

The order of the evaluation of expressions is decided according to the operator precedence. However, the operator precedence is overruled by the usage of parentheses.

Thus in an expression the parentheses sub expressions will be evaluated first. The operations of same priority are performed from left to right.

Unary operators are operated from right to left.

Type ConversionThe process in which one pre-defiend type of expression is converted into another type is called conversion. there are two types of conversion in C++.

Implicit (automatic) conversion and Explicit Conversion.

The process of converting one predefined type of expression into another is called type conversion.

Type Combatibility

In an assignment statement, the variables of one type can be used with variables of some other type applying rules of type conversion. The value on the right-hand side of an assignment statement is converted into the type of the left-hand side.

HOME LEARN C++ PREVIOUS NEXT