-1

i started to learn a bit more about c++ and lately i see really often stuff like (DWORD)(x+y);

example:

    int number = 10;
int pointer;

pointer = *(int*)(number);

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

getchar();

this makes a exception, i know, but could someone properly explain those action to me? like (int) and (DWORD) etc.. or, recommend me a book? thanks!

Simon Soka
  • 69
  • 10

1 Answers1

2

Casting or type conversion is changing a variable from one datatype to another. There are two types. implicit and explicit casting.

Implicit type conversion, also known as coercion, is an automatic type conversion by the compiler.

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

Explicit type conversion is a type conversion which is explicitly defined within a program

int a = 3;
double b = (int)a; //convert 'a' explicitly from 'int' to 'double'

A DWORD is a 32-bit unsigned integer. I'ts just another type. A pointer is another datatype.

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

About cating: https://en.wikipedia.org/wiki/Type_conversion#Implicit_type_conversion About book recommendation: The Definitive C++ Book Guide and List

Community
  • 1
  • 1
Acha Bill
  • 1,255
  • 1
  • 7
  • 20