Sections


Main-Menu

header image

Type Casting


Type Conversion (Type Casting)

When an expression of a given type is converted into another type, then this process is known as type-casting.

Type conversion can be

•    Implicit conversion.
•    Explicit conversion.

Implicit Conversion

Implicit Conversion are automatically performed when a value is copied to a compatible type, they do not require any operator.

For example:

int a;
float b=5.55555;
a=b;

Here the value of b is converted to integer before being assigned to a. Thus the fractional part of b is truncated.

Explicit Conversion

Many conversions, especially those that imply a different interpretation of the value, require an explicit conversion. Two notations for explicit type conversion are functional and c-like casting.

For example:

short a=5000;
int b;
b = (int) a;    // c-like cast notation
b = int (a);    // functional notation


Related Articles :



Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Shaadi.com Matrimony - Register for FREE