Types:

1. What is Type Casting?

Type casting refers to converting a variable from one type to another.


2. Implicit Casting (Coercion)

int i = 10;
double d = i;  // int automatically promoted to double


3. Explicit Casting

Manual casting using casting operators.

C++ provides four explicit casting operators:

Cast Type Purpose Syntax
static_cast Safe compile-time conversions static_cast<NewType>(value)
dynamic_cast Safe downcasting in polymorphic types dynamic_cast<NewType*>(ptr)
const_cast Add/remove const qualifier const_cast<NewType>(value)
reinterpret_cast Reinterpret memory bits (low-level) reinterpret_cast<NewType>(value)

4. Details of Casting Types