Loading...
C++

Expressions of C++

A combination of variables, constants, and operators that represent a computation forms an expression. Depending upon the type of operands involved in an expression or the result obtained after evaluating expression, there are different categories of an expression. These categories of an expression are discussed below.

  • Constant Expression:
    The expressions that comprise only constant values are called constant expressions. Some examples of constant expressions are 10,  ‘A’ etc.
  • Integral Expression:
    The expressions that produce an integer value as output after performing all types of conversations are called integer expressions. For example,  a, 6*a-b and 5 +int(2.0) are integral expressions. Here, a and y are variables of type into.
  • Float Expressions:
    The expressions that produce floating-point values as output after performing all type of conversions are called float expressions. For example, 5.9, a-b and 9+float(6) are float expressions. Here, x and y are variables of type float.
  • Relational or Boolean Expressions:
    The expressions that produce a bool type value, that is, either true or false are called Relational or Boolean Expressions. For example, a<b, x>10, a==b and a<=b are relational expressions.
  • Logical Expressions:
    The expressions that produce a bool type value after combining two or more relational expressions are called logical expressions. For example, a==10, &&m==5 and m==n are logical expressions.
  • Bitwise Expressions:
    The expressions which manipulate data at bit level are called bitwise expressions. For example, x>>2 and y<<4 are bitwise  expressions.
  • Pointer Expressions:
    The expressions that give address values as output are called pointer expressions. For  example, &a, ptr and -ptr are pointer expressions. Here, a is a variable of any data type and ptr is a pointer.
  • Compound Assignment:
    Compound assignment is an assignment expression, which uses a compound assignment operator that is a combination of the assignment operator with a binary arithmetic operator. For example,
    a+=10; //equivalent to a=a+10
    In this statement, the operator += is a compound assignment operator, also known as short-hand assignment operator.
Leave a Reply

Your email address will not be published. Required fields are marked *