微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – 这种动态分配有什么作用?

今天,我发现你可以在C中编写这样的代码并编译它:
int* ptr = new int(5,6);

这样做的目的是什么?我当然知道动态的新int(5),但在这里我迷失了.有线索吗?

解决方法

您正在使用逗号运算符,它仅计算一个值(最右侧).

The comma operator (,) is used to
separate two or more expressions that
are included where only one expression
is expected. When the set of
expressions has to be evaluated for a
value,only the rightmost expression
is considered.

Source

指针指向的内存地址初始化为上面的值6.

原文地址:https://www.jb51.cc/c/116500.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐