Static casting

Static casting is when you want to convert one type into another, static casting is used allot of the time without even knowing. For example

int value = 2;
float t = float(value);

the float(value) is a static casting of converting one value into another. Below is a full code example

#include <iostream>
 
using namespace std;
int main()
{
	int i = 3;
	// the float(<value)> is basically a static cast from a interger value into a float
	cout << float(i) << endl;
	cout << static_cast<float>(i) << endl;
}

It is very small since static_cast’ing is very basic in nature, but the only problem is that you have to check to make sure that there is a error e.g not NULL.

Leave a Reply

Your email address will not be published. Required fields are marked *