C++ Program to use Different Formats of type casting and display the converted values


In this Program, You will learn how to use Different Formats of type casting and display the converted values in C++.


int x = 10;

char ch = char(x);


Example: How to use Different Formats of type casting and display the converted values in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int a = 66;
    float f = 3.4;
    double d = 67.89;
    char c = 'd';

    cout << "\n int in char Format is :" << char(a);
    cout << "\n float in int Format is :" << int(f);
    cout << "\n double in char Format is :" << char(d);
    cout << "\n char in int Format is :" << int(c);

    return 0;
}

Output:

int in char Format is :B
float in int Format is :3
double in char Format is :C
char in int Format is :100