cast.cpp

来自「这是一个C++的比较简单的例子,使用于初学者,建议入门级的人看看.」· C++ 代码 · 共 27 行

CPP
27
字号
// cast.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	// static_cast
	float f=5.5 ;
	int n=static_cast<int>(6.7) ;	
	cout<<n<<endl;	
	
	// reinterpret_cast
#if 0
//	int *p=static_cast<int*>(n);
	int *p=reinterpret_cast<int*>(n);
	cout<<p<<endl;
	
	int n1=reinterpret_cast<int>(p);
	cout<<p<<endl;
#endif
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?