How can I print the address of first character?

后端 未结 1 1215
攒了一身酷
攒了一身酷 2021-01-02 23:47

Why the entire string is displayed as outcome? Why address of 1st character not getting printed? How can I print address of 1st character? Please help me.

#         


        
1条回答
  •  粉色の甜心
    2021-01-03 00:19

    The << operator on std::cout will treat a char* as a null-terminated string. You will need to cast it to a void* to print the pointer value.

    Try this:

    #include 
    
    int main()
    {
        char x[6] = "hello";
        std::cout << static_cast(x);
    }
    

    0 讨论(0)
提交回复
热议问题