【问题标题】:What will this do? C++ [closed]这会做什么? C++ [关闭]
【发布时间】:2023-03-12 19:44:01
【问题描述】:
void main()
{
    int const *p=5;
    cout<<++(*p);
}

这会做什么?错了吗?如果错了,为什么?请让我明白。谢谢!

【问题讨论】:

  • 它会让你投反对票。为避免将来出现这些情况,您应该使用the tour 并阅读help page。这里是The Definitive C++ Book Guide and List
  • 我做错了什么?我是新来的,请解释一下!谢谢
  • 当您尝试编译这段代码时,您的编译器会说什么?
  • 我做错了什么?嗯..首先 - 你在这里问之前没有做任何研究。

标签: c++ pointers constants


【解决方案1】:

这会做什么?

程序格式错误,可能拒绝编译。如果它编译,则标准未指定行为。

错了吗?如果错了,为什么?

是的。因为:

error: '::main' must return 'int'
error: invalid conversion from 'int' to 'const int*'
error: 'cout' was not declared in this scope
error: increment of read-only location '* p'

【讨论】:

    猜你喜欢
    • 2017-02-09
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多