How to print the address of the first character?

Why is the whole row displayed as a result? Why is the 1st character address not printed? How can I print the address of the 1st character? Please help me.

#include <iostream>
int main()
{
    char x[6]="hello";
    std::cout<<&x[0];
}
+4
source share
1 answer

The operator <<on std::coutwill process char*as a zero-terminated string. You will need to send it in void*to print the pointer value.

Try the following:

#include <iostream>

int main()
{
    char x[6] = "hello";
    std::cout << static_cast<void*>(x);
}
+6
source

Source: https://habr.com/ru/post/1583922/


All Articles