C++ 强转注意问题

// test.cpp : 定义控制台应用程序的入口点。
//

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

typedef union tagGameAttributeValue
{
	int				nValue;
	unsigned int	uValue;
	float			fValue;
	bool            bValue;
	struct 
	{
		short wLo;
		short wHi;
	};
	struct 
	{
		unsigned short uwLo;
		unsigned short uwHi;
	};
	struct  
	{
		char cLoLo;
		char cLoHi;
		char cHiLo;
		char cHiHi;
	};
	struct  
	{
		char btLoLo;
		char btLoHi;
		char btHiLo;
		char btHiHi;
	};

	struct 
	{
		unsigned short     wValueLo;
		struct
		{
			unsigned char btValueHiLo;
			unsigned char btValueHiHi;
		};
	};
}GAMEATTRVALUE, *PGAMEATTRVALUE;

int _tmain(int argc, _TCHAR* argv[])
{
	GAMEATTRVALUE	value;		//属性值
	value.nValue = 7;
	float percentage = (float)5/10;				//percentage = 0.5
	//float percentage = (float)(5/10);			//percentage = 0
	value.nValue = value.nValue * percentage;
	printf("%d
",value.nValue);
	system("pause");
	return 0;
}


原文地址:https://www.cnblogs.com/byfei/p/14104265.html