You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将数组地址存入uintptr_t后读取内存输出乱码的问题求助

将数组地址存入uintptr_t后读取内存输出乱码的问题求助

各位好,我在C++里处理数组地址的时候碰到了一个问题,想请大家帮忙分析下。

我先是创建了一个char数组,然后尝试把它的地址存到uintptr_t类型的变量中,代码如下:

static char* NewArray = new char[2];
NewArray[0] = 'A';
NewArray[1] = 'B';
uintptr_t C = reinterpret_cast<uintptr_t>(&NewArray);

之后我想用这个uintptr_t变量来读取数组里的内容,于是写了这段代码:

std::cout << *reinterpret_cast<char*>(C);

但运行后输出的是乱码,完全不是我预期的'A'。有没有人能指出我哪里写错了呀?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 12:53:00