The Big Master

Type casting

In C++, type casting, also known as type conversion, is the process...

In C++, type casting, also known as type conversion, is the process of explicitly converting one data type to another. It allows you to change the interpretation or representation of a value to match a different type. Type casting is useful when you need to perform operations or assignments involving variables of different data types, or when you want to ensure compatibility between different types in an expression.

#include <iostream>
using namespace std;
int main() {
    double d = 3.14159;
    int x = int(d);       		 // Explicit conversion from double to int
    cout << "double Value: " << d << endl;
    cout << "int Value: 	  " << x << endl;
    return 0;
}