簡體   English   中英

如何打印第一個字符的地址?

[英]How can I print the address of first character?

為什么整個字符串顯示為結果? 為什么第一個字符的地址沒有被打印? 如何打印第一個字符的地址? 請幫我。

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

std::cout上的<<運算符將char*視為以null結尾的字符串。 您需要將其強制轉換為void*以打印指針值。

試試這個:

#include <iostream>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM