How to display the addresses in char *b[4] using cout?

Hi, I'm doing some tests on arrays and pointers. I wonder how cout can display the contents of an array of pointers.
Thanks.

1
2
3
4
5
6
7
8
    char aa[] = {'a', 'b', 'c', 'd'};
    char *bb[4];

    for(int i = 0; i < 4; i++){
        bb[i] = &aa[i];
        cout << bb[i] << endl; //this does not show the addresses
        printf("%x\n",bb[i]);
    }


Try playing with the & operator a bit and see if you can't figure it out based on that.
Thanks for the reply.

I tried that but it did not work. I'm curious, as I understand it, the contents of the array are already addresses. Therefore, prefixing the array by the reference operator & would show the address of each array element and not the address content of each array element?
If you want to use cout to print char* as an address you need to cast the pointer to some
other pointer type - for example cast it to a void*

 
cout << static_cast<void*>(bb[i]) << endl; // 
static_cast works. Thanks!
please mark as solved.
Topic archived. No new replies allowed.