C++ Cast

Explicit type conversion (casts) in c++ or c++ cast
It is user defined conversion that forces an expression to be of specific type. It is applied when a programmer needs to convert a value from one type to another. This conversion is also called type casting and it is done using type_cast operator. i.e. () that is used as:-

(Type) expression

Where type is a valid c++ data type to which the conversion is to be done.

To determine the use of the cast operator, let us consider the following example.

Char ch;
Float abc;
Int x, y, z;
x= (int) ch;

Where ch is a character variable and force to convert as the integer data type.

abc= (float) (y*z);

Where the expression (y*z) is an integer data type and force to covert as a floating point number. Using cast operation we can easily force an expression of specific type.

Related posts:

  1. Type Conversion In C++ Type Conversion In C++ This process of converting one predefined...
  2. Predefined Data Types Predefined data types Data can be of many types (e.g....
  3. Object oriented programming Object oriented programming : The main idea behind object oriented...
  4. Procedural oriented programming Procedural oriented programming (pop):- A program in a procedural language...