小编Bil*_*rok的帖子

为什么这个C++函数返回一个值?

为什么这段代码打印出n-100?

    int hello(int n)
    {
        for(int i = 0; i < n-100; i++)
        {
        }
    }

    int main()
    {
            int h = hello(12);
        cout << hello(12) << " " << h << endl;
    }
Run Code Online (Sandbox Code Playgroud)

然而,这两个函数都返回垃圾(分别为2665092和0)

    int hello1(int n)
    {
          for(int i = 0; i < 12; i++);
    }


    int hello2(int n)
    {
         (n - 100);
    }
Run Code Online (Sandbox Code Playgroud)

我在cygwin环境中使用g ++编译了这段代码.

c++ for-loop function

1
推荐指数
1
解决办法
101
查看次数

标签 统计

c++ ×1

for-loop ×1

function ×1