c++的数据类型的引用(三种方式有一些区别)

来源:互联网 发布:关键词软件 编辑:程序博客网 时间:2024/06/05 12:13
#include "iostream"
using namespace std;
struct stu
{
int age;
};
void test(stu *a){
(*a).age=20;
}
void test1(stu &a){
a.age=100;
}
void test2(stu a){
a.age=200;
}
void main(){
stu a;
test(&a);
cout<<"a的值为:"<<a.age<<endl;
test1(a);
cout<<"a的值为:"<<a.age<<endl;
test2(a);
cout<<"a的值为:"<<a.age<<endl;
system("pause");
}
阅读全文
0 0
原创粉丝点击