Skip to main content

Casting

Definition:
Manually converting a value from one data type to another.


Detailed Explanation

  • Explicitly tells the compiler to treat a value as a different type.
  • Can be safe (widening) or unsafe (narrowing with possible data loss).
  • Often required when working with mixed types.

Example

// Casting double to int // double pi = 3.14; // int whole = (int) pi;


⬅ Back