小编use*_*114的帖子

如何在没有参考的情况下更改局部变量

面试问题:不使用引用作为函数自变量或从函数返回值而更改局部变量值

void func()
{
  /*do some code to change the value of x*/
}
int main()
{
   int x = 100;
   printf("%d\n", x);  // it will print 100
   func(); // not return any value and reference of x also not sent
   printf("%d\n", x);  // it need to print 200
}
Run Code Online (Sandbox Code Playgroud)

x 价值需要改变

c

-6
推荐指数
3
解决办法
249
查看次数

标签 统计

c ×1