是” const wchar_t*"指针?
通常,当我们编写时:
int a = 10;
int* ptr = &a;
std::cout << *ptr;
代码输出是:
> 10
但是当我编写这篇文章时:
const wchar_t* str = L"This is a simple text!";
std::wcout << str << std::endl;
std::wcout << &str << std::endl;
代码输出为:
> This is a simple text!
> 012FFC0C
这使我感到困惑。
- 那个星号符号不是指针吗?
- 如果是指针,我们如何分配一个值 比地址值?
- 最高输出不应该在底部和 顶部的底部输出?
Normally when we write:
int a = 10;
int* ptr = &a;
std::cout << *ptr;
Code output is:
> 10
But when I write this:
const wchar_t* str = L"This is a simple text!";
std::wcout << str << std::endl;
std::wcout << &str << std::endl;
Code output is:
> This is a simple text!
> 012FFC0C
So this makes me confused.
- Doesn't that Asterisk symbol stand for pointer?
- If it is a pointer, how is it possible for us to assign a value other
than the address value? - Shouldn't the top output be at the bottom and
the bottom output at the top?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
l“这是一个简单的文本!”
是类型const wchar_t [23]
包含所有字符串字符以及终止0 char的数组。数组可能会衰减,在这种情况下,它们变成了std :: Wout
中发生的情况,可以与&lt;&lt;&lt;
一起使用。运算符将如此无效的终止字符作为第二操作数;该操作员打印字符串。第二个打印只是打印指针的地址,因为
&lt;&lt;&lt;
运算符处理类型const wchar_t **
与任意指针有不同的特点的运算符,因此没有超载的过载。类型(除了第一个打印中所示的某些特定指针类型外)。L"This is a simple text!"
is an array of typeconst wchar_t[23]
containing all the string characters plus a terminating 0 char. Arrays can decay in which case they turn into a pointer to the first element in the array which is what happens instd::wout
can be used with a<<
operator that takes such a null terminated character as second operand; this operator prints the string.The second print simply prints the address of the pointer, since there is no overload for the
<<
operator handling an argument of typeconst wchar_t**
differently to arbitrary pointer types (except for some specific pointer types as seen in the first print).