/*
类型强制转换后 本身类型不变
*/
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <ctime>
#include <Windows.h>
#include <typeinfo>
using namespace std;
int main()
{
int* p1 = new int;
void* p2;
cout << "The type of p1 is " << typeid(p1).name() << endl;
cout << "The type of p2 is " << typeid(p2).name() << endl;
double* p3 = (double*)p1;
cout << "The type of p3 is " << typeid(p3).name() << endl;
int a = 1;
double b = (int)a;
cout << "The type of a is " << typeid(a).name() << endl;
cout << "The type of b is " << typeid(b).name() << endl;
cout << "The type of a is " << typeid(a).name() << endl;
}类型转换
最新推荐文章于 2025-06-03 00:51:08 发布
本文通过实例演示了C++中不同类型指针之间的强制转换过程,并解释了整型变量到浮点型变量的转换机制。展示了即使经过类型转换,原始变量的类型保持不变的特点。
8462

被折叠的 条评论
为什么被折叠?



