C++ Expression and there types

C++ Expression and there types

An expression is a combination of operators, constants and variables arranged as per the rules of the c language. it may include function call which return values. An expression may consist of one or more operands, and one or more then one operators to produce a value. Expressions may be of the following seven types.

1. constant expressions.
2. Integral Expressions.
3. Float expressions.
4. pointer Expression.
5. Relation Expression.
6. Logical expression.
7. Bitwise expression

As expression may also use combination of the above expressions. Such expressions known as compound expressions

Constant Expressions

constant expression consist of only constant values Example

20
20+6/2.0
‘x’

Integral Expression

Integral Expressions are those which produce integer result after implementing all the automatic and explicit type conversions Examples

m * n – 5
m * ‘x’
5+ int(2.0)

where m and n are integers variables

Float Expressions

Float Expressions are those which, after all conversions, produce floating-point result. Example

x+y
x*y/10
5+float(10)
10.75

where x and y are float variables

pointer Expressions:

pointer Expressions produce address values Examples

&n
ptr
ptr+1
“xyz”

where n is a variable and ptr is a pointer variable

Relation Expressions

Relation Expressions yield result of type bool which takes a value true or false Example

x<=y
y>=x
a-b>17
n+n<90

When Arithmetic expressions are used on either side of a relation operator, they will be evaluated first and then the result compared. Relational expressions are also known as boolean expression

Logical Expressions:

Logical Expression combine two or more relational expression and produces bool type results Example

x>y && x==19
x==90 || y==9

Bitwise Expressions

The Bitwise Expression are used to manipulate data in bit level. they are generally used for testing or shifting bits for Examples
x<<4 // shift four bit position to the left
y>>1 // shift one bit position to the right
shift operators are often used for multiplication and division by power of two.

ANSI C++ has introduced what are termed as operator keywords that can be used as alternative representation for operator symbols, operator keywords are given in next

Special Assignment Expressions:

chained Assignment
x=(y=5);
x=y=10;

First 10 is assigned to y and then to x

a chained statement cannot be used to initialized variables at the time of declaration for instance the statement

float a=b=13.78; // this is wrong

is illegal. This may be written as
float a=13.78,b=13.78; // this is correct

Embedded Assignment:

x=(y=60)+20;
(y=60) is an assignment expression know as embedded assignment. Here the value 60 is assigned to y and then the result 60+20=80 is assigned to x. This statement is identical to

y=60;
x=y+20;

compound assignment:

like the c, c++ supports a compound statement operator which is a combination of the assignment operator with a binary arithmetic operator. for example , assignment statement examples below
y=y+20;
may be written as
y+=20;

The operator +=is known as compound assignment operator. The general form of the compound assignment operator:
variable opt=variable2;
where opt is binary arithmetic operator. This means that
variable1=variable opt variable2;

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise