gpt4 book ai didi

C++ : Using void to create variables

转载 作者:太空狗 更新时间:2023-10-29 19:57:49 25 4
gpt4 key购买 nike

我正在通过互联网自学 C++。我想知道您是否可以创建 void 类型的变量。如果是这样,你怎么能?这些变量还有什么用?

这不起作用:

void b;
cout<<b;

错误:

Size of b is unknown or zero

谢谢:)

最佳答案

"I was wondering if you can create a variable of the void type."

不,编译器已经告诉你了。

If so , how can you?"

见上文。

"Also what will be these variables used for?"

它不会有用,因为 void 明确指定无类型


"so wat is a void pointer used for?"

至于你的评论:

它用于存储任何类型对象的地址。除非您不知道确切的原始类型,否则它也没什么用。

关于C++ : Using void to create variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29319869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com