c语言 什么时候要传入参数的引用“&” —— 对参数的修改结果需要“带回来

 

实例:

#include <stdio.h>
void test(int x)
{
  
   x= 2020;
   printf("test内部 x=%d\n",x);
}
int main()
{
   int  x = 1024;
   test(x);
   printf("test调用后x=%d\n",x);
}

 

 

 

实例:

 

#include <iostream>
using namespace std;
#include <stdio.h>
void test ( int & x )
{
  
   x= 2020;
   printf("test内部 x=%d\n",x);
}
int main()
{
   int  x = 1024;
   test(x);
   printf("test调用后x=%d\n",x);
}

 

 

这里看出来  & 传入 可以 改变 值 

posted @ 2021-01-06 15:09  1点  阅读(596)  评论(0编辑  收藏  举报