Explain various types of expressions in C++

Estudies4you
Q18. Define an expression. Explain various types of expressions.
Answer :

Expression
An expression consists of a single entity such as a constant, a variable or it can be a combination of such entities joined together using one or more operators.

Examples
x = y;
c = a + b * d;

Types of Expressions
(i) Constant expressions
(ii) Float expressions
(iii) Integral. expressions
(iv) Pointer expressions
(v) Relational expressions
(vi) Logical expressions
(vii) Bitwise expressions
(i) Constant Expression
An expression which consists of only constants (i.e., numbers, characters, special symbols) is called as constant expression.
Examples
5 + 15/7
“xyz”
"$"

(ii) Float Expression
An expression which produces floating point values after performing all the evaluations is called as float expression.
Examples
7.0 + float(5)
15.75

(iii) Integral Expression
An expression which produces integral values after performing all the automatic and explicit type conversions is called as integral expression.
Examples
4+ int(7.0)
5 —'x’

(iv) Pointer Expression
An expression which produces the address value is called as pointer expression.
Examples
&x
&p + 1

(v) Relational Expression
An expression which contains relational operators like <, <=, >, >= and produce a boolean value after evaluation is called as relational expression.
Examples
a <= b
x + y > c

(vi) Logical Expression
An expression which combines two or more relational expressions with logical operators and produces boolean values is called as logical expression.
Examples
x > y && x = =10
a = =20 && a > b

(vii) Bitwise Expression
An expression which performs manipulation on bits stored in memory is called as bitwise expression.
Examples
a<<2
p>> 1


To Top