智慧云教育平台app:VB引用调用和按值调用的区别

来源:百度文库 编辑:中科新闻网 时间:2024/05/08 14:27:49
VB引用调用和按值调用的区别

引用可以改变原变量
传值是复制一份原变量的拷贝不改变原变量
eg:
void max(int& a,int& b)
{
int temp=a;
a=b;
b=temp;
}
void max2(int a,int b)
{
int temp=a;
a=b;
b=temp;
}
void max3(int* a,int* b)
{
int temp
temp=*a
*a=*b;
*b=temp}
main()
{
int a=2,b=3;
max(a,b);//交换了a/b
printf("%d %d",a,b);
max2(a,b);//没改变
printf("%d %d",a,b);
max3(&a,&b);//改变了
printf("%d,%d",*a,*b);
}