Because a char is not a string.
And because integers are not stored in memory as strings.
Casting a void pointer is like doing a reinterpret_cast. That is... it's looking at that area in memory and reinterpretting the binary data as if it were some other type.
Assuming you have 32-bit integers and are on a little endian system... the integer 100 is stored in memory like so:
64 00 00 00
That's 4 bytes, with the low byte stored first (100 == 0x00000064)
In a completely unrelated happenstance... the ASCII code for the letter 'd' is also assigned a value of 100 (0x64). You can test this for yourself:
|
if( 'd' == 100 ) { /* this code will execute*/ }
|
So when you have a pointer that's looking at memory containing
64 00 00 00
, and you tell it "hey... reinterpret that data as if it were a bunch of chars"... it's going to do exactly that.
64 00 00 00
becomes "d\0\0\0" (the letter 'd' followed by 3 null characters)
Because "d\0\0\0" is
ALSO stored in memory as
64 00 00 00
So yeah... using void pointers and casting around C++'s type system is not a good idea unless you know what you're doing. And even if you do know what you're doing, it's still ill advised.