#include<iostream>
using namespace std
;
struct student
{
char name
[100];
int age
;
};
void print_info(struct student
*p
)
{
cout
<< "姓名:" << p
->name
<< " " << "年龄:" << p
->age
<<endl
;
}
void print_info1(struct student s
)
{
cout
<< "姓名:" << s
.name
<< " " << "年龄:" << s
.age
<< endl
;
}
void print_info2(struct student
&s
)
{
cout
<< "姓名:" << s
.name
<< " " << "年龄:" << s
.age
<< endl
;
}
int main(void)
{
student stu
= { "zhx",25 };
print_info(&stu
);
print_info1(stu
);
print_info2(stu
);
system("pause");
return 0;
}
这里定义了一个结构体,引用相对于指针来讲稍微简单一些,是变量的别名,应当注意使用引用。
转载请注明原文地址:https://blackberry.8miu.com/read-28570.html