//函数返回结构的使用示例
2012-06-04 12:24
211 查看
//函数返回结构的使用示例 #include<iostream.h> #include<conio.h> struct student { int num; char name[20]; char sex; float score; }; student getstudent(); void displaystudentinfo(const student &stud); int main() { student thestud={102,"li xiao ming",'M',92}; cout<<"Intial student information:"; displaystudentinfo(thestud); thestud=getstudent(); //将右边结构类型的成员整体赋给左边 cout<<"\nAfter call getstudent:"; displaystudentinfo(thestud); getch(); return 0; } student getstudent() //返回值为student 型 { student stud; cout<<"Please enter the number:"; cin>>stud.num; cout<<"Please enter the name:"; cin>>stud.name; cout<<"Please enter the sex:"; cin>>stud.sex; cout<<"Please enter the score:"; cin>>stud.score; return stud; //返回值仍然为值传递,类似return n(n为整型等基本数据类型); } void displaystudentinfo(const student &stud) //用传引用的方式 输出原始信息 ,为防止原数据被修改用const进行限定 { cout<<endl; cout<<"num="<<stud.num<<"\t"; cout<<"name="<<stud.name<<"\t"; cout<<"sex="<<stud.sex<<"\t"; cout<<"score="<<stud.score<<"\t"<<endl; }
相关文章推荐
- 郝斌数据结构 10 跨函数使用内存讲解及其示例
- 【Python】Pandas 的 apply 函数使用示例
- flock()函数使用示例
- JavaScript的函数使用的示例
- boost库学习随记六:使用同步定时器、异步定时器、bind、成员函数回调处理、多线程的同步处理示例等
- 【ZZ】一些在php中使用header函数设置http头的示例方法
- java使用泛型实现栈结构示例分享
- C#调用C++方法,C#使用c++方法返回类或结构体
- JavaScript DOM 中setAttribute()的使用 以及点击鼠标返回函数的处理
- PHP 使用header函数设置HTTP头的示例解析 表头
- PCRE函数简介和使用示例
- php示例代码之使用list函数和mysql_fetch_row函数
- 个人使用的Java rest接口返回结构
- PHP使用CURL函数获取HTTPS网页及POST数据示例
- 在C#中如何在函数参数中返回结构数组?
- [Linux流操作]使用feof和ferror函数判断当前返回的错误
- LigerUi中,使用LG.ajax返回JSON提示信息的Asp.Net拼法(示例,应该能看明白吧)
- 解决Java程序使用MySQL时返回参数为乱码的示例教程
- Shell脚本中使用function(函数)示例
- Node.js 使用angularjs取得Nodejs http服务端返回的JSON数组示例