Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
#include <iostream>
extern "C" {
int toInt(float a)
{
int *b = (int *)&a;
return *b;
}
}
int main()
{
float x = 65.315f;
int a = (int)x;
int b = (int&)x;
int c = reinterpret_cast<int &>(x);
int &d = reinterpret_cast<int &>(x);
std::cout << x << '\n' << a << '\n'
<< b << '\n' << c << '\n' << d << std::endl;
d = 50;
std::cout << d << '\n' << x << '\n'
<< b << '\n' << c << std::endl;
const float z = 10.11f;
int e = reinterpret_cast<const int &>(z);
const int &f = reinterpret_cast<const int &>(z);
std::cout << e << '\n' << f << std::endl;
int g = toInt(x);
int h = toInt(z);
std::cout << g << '\n' << h << std::endl;
return 0;
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more