Why at runtime do I get a different value when I enter a string in a DWORD?

std::cout << (DWORD)"test";

If I compile and run this, I get different output values ​​each time, but I can’t understand why.

Any ideas?

PS: I am using the 64-bit version of Windows 7 and I am compiling it with Microsoft Visual C ++ 2010 Ultimate.

+5
source share
2 answers

"test", in your code, is actually a pointer to the beginning of a line. When you click on it DWORD, you will draw a pointer to an integer type and write this number.

Since the memory cell that stores the “test” may change with each run, the value you see will change.

+4
std::cout << (DWORD)"test";

:

const char *tmp = "test";
std::cout << (DWORD)tmp; 

, DWORD:

, :

std::cout << (const void*)"test";
+2

All Articles