why use (void *) to display char arrays' addr?

and (int *) works, too. How to understand this usage?

1
2
char arr[20] = "Hello!";
cout << (void *) arr;


i mean why void and int other than double or long something?
Last edited on
anybody?
It seems to be doing the same as this. That's the address of the array in both cases. Why it uses void. Idk.

1
2
3
4
5
6
7
8
#include <iostream>

int main()
{
    char arr[20] = "Hello!";
    std::cout << (void *)arr << " " << &arr;
    return 0;
}


I tried a google search and it sounds a void pointer has something to do with dynamic memory.
Last edited on
The purpose is so cout will output the address stored by the pointer; if you pass a char* it has special behavior that treats it as a C-string and outputs the characters at the memory address as though they were a C-string. This is not what you want if you want to see the address of the string, so you cast to a different pointer type to get the desired behavior.
oic thx :>
Topic archived. No new replies allowed.