如何打印char数组的地址 [英] How to print the address of char array
本文介绍了如何打印char数组的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
int main(int argc, char** argv)
{
float *f = new float[10];
std::cout << f << std::endl;
std::cout << f + 3 << std::endl;
char *c = new char[10];
std::cout << c << std::endl; // no print
std::cout << c + 3 << std::endl; // no print
return 0;
}
stdout
0x2b3cbaf1bc20
0x2b3cbaf1bc2c
如何打印char数组的地址?
How to print the address of char array?
推荐答案
您需要转换为 void *
调用操作符<<
的正确重载,而不是作为C字符串输出
You need to cast to void*
to invoke correct overload of operator <<
instead of outputting as C strings
std::cout << static_cast<void*>(c) << std::endl;
std::cout << static_cast<void*>(c+3) << std::endl;
这篇关于如何打印char数组的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文