An Expression is a combination of operators, constants and variables arranged as per rules of language. It may also include function calls which return values. An expression may consist of one or more operators and zero or more operator to produce value.
Types of expressions
Expression may be of following four types:
It produces an integral result after implementing all the automatic and explicit types conversions.
where m and n are integral variables.
2. Integral expression.
3. Floating expression.
After all conversion, these produce floating point results.
4. Pointer expression.
It produces address value.
ptr where m is variable and ptr is a pointer
ptrH ptr is a pointer
We can mix data types in expression
is a valid statement.
Whenever data type are mixed in an expression, C++ performs the conversions automatically.This process is called implicit or automatic conversion.
Rule:"smaller"type is converted to the "wider" type.
e.g. waterfall model. If one operator is an int and other is float, then int is converted into float because a float is wider than an int.
Whenever a char and short int appear in an expression, it is converted into an int. This as called integral widening conversion.
The implicit conversion is applied only after completing all integral widening conversions.