Type Conversion in C++

 Converting an expression of a given type into another type is known as type-casting or type conversion.
 Type conversions are of two types, they are
1. Implicit Conversion
2. Explicit Conversion

 Implicit Conversion
        Implicit Conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. The C++ compiler will implicitly convert or promote values if it can be done safely. If not it will generate a warning or an error depending on the conversion required.
 For Example
short a = 2000;
int b;
b = a;

 Explicit Conversion
 C++ is a strong-typed language. Many coversions, eqpecially those that imply a different interpretation of the value, require an explicit conversion.
 For Example
short a = 2000;
int b;
b = (int) a; //c-like cast notation
b = int (a) // functional notation

Type Conversion in C++ Type Conversion in C++ Reviewed by Unknown on 04:26 Rating: 5

No comments:

Powered by Blogger.