用指向结构体变量指针作实参
来源:互联网 发布:程序员修炼之道kindle 编辑:程序博客网 时间:2024/06/05 12:03
// 121210 第七章例7.31.cpp : 定义控制台应用程序的入口点。///* * Copyright (c) 2012, 烟台大学计算机学院 * All rights reserved. * 作 者: 刘同宾 * 完成日期:2012 年 12 月 10 日 * 版 本 号:v1.0 * * 输入描述: * 问题描述: 用指向结构体变量指针作实参* 程序输出:* 问题分析:略 * 算法设计:略 */#include "stdafx.h"#include<iostream>#include<string>using namespace std;struct student{int num;string name; //用string类型定义字符串变量float score[3];}stu={12345,"liutongbin",99.2,98.1,97.8};//定义结构体student变量stu并赋初值int main(){void print(student *); //函数声明,形参为指向student类型数据的指针变量student *pt=&stu;//定义基类型为student的指针变量pt,并指向stuprint(pt); //实参为指向结构体stu指针变量return 0;}void print(student *p){cout<<p->num<<" "<<p->name<<" "<<p->score[0]<<" "<<p->score[1]<<" "<<p->score[2] <<endl;}