A void pointer, (void *) is a raw pointer to some memory location.
The type void * simply means “a pointer into memory; I don’t know what sort of data is there”.
1 2 3 4 5 6 |
char i = 'a'; std::cout << "address of i is: " << (void*)&i << std::endl; std::cout << "address of i is: " << (void*)(&i - 1) << std::endl; //address - 1 byte std::cout << "address of i is: " << (void*)(&i + 1) << std::endl; |
note:
When you stream the address of a char to an ostream, it interprets that as being the address of the first character of an ASCIIZ “C-style” string, and tries to print the presumed string. You don’t have a NUL terminator, so the output will keep trying to read from memory until it happens to find one or the OS shuts it down for trying to read from an invalid address. All the garbage it scans over will be sent to your output.
When you are taking the address of i, you get char *.
operator<< interprets that as a C string, and tries to print a character sequence instead of its address.