使用*(datatype *)的数据类型指针

时间:2015-09-25 18:53:19

标签: c++

我开始学习更多关于c ++的知识,最近我经常看到像(DWORD )(x + y)这样的东西;

示例:

    int number = 10;
int pointer;

pointer = *(int*)(number);

std::cout << "number: " << number << std::endl;
std::cout << "pointer: " << pointer << std::endl;

getchar();

这是一个例外,我知道,但有人可以正确地向我解释这些行动吗?喜欢(int )和(DWORD )等..或者,推荐我一本书?谢谢!

1 个答案:

答案 0 :(得分:2)

转换或类型转换正在将变量从一种数据类型更改为另一种数据类型。 有两种类型。 implicitexplicit投射。

Implicit类型转换,也称为coercion,是编译器的自动类型转换。

double a = 3.4;
int b = a; //convert 'a' implicitly from 'double' to 'int'

Explicit类型转换是在程序

中明确定义的类型转换
int a = 3;
double b = (int)a; //convert 'a' explicitly from 'int' to 'double'

DWORD是32位无符号整数。我只是另一种类型。 指针是另一种数据类型。

void *a;
int *b = (int*)a; //explicit
void *c = b; //implicit

关于cating:https://en.wikipedia.org/wiki/Type_conversion#Implicit_type_conversion 关于图书推荐:The Definitive C++ Book Guide and List