/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者:解晓东
* 完成日期:2012 年 12 月 6 日
* 版 本 号:v1.0
*
* 输入描述:
* 问题描述:指向结构体变量的指针
* 程序输出:
* 问题分析:
* 算法设计:
*/
#include <iostream>
using namespace std;
struct student
{
int num; /*学生学号*/
char name[20]; /*学生姓名*/
char sex; /*学生性别*/
int age; /*学生年龄*/
float score; /*学生成绩*/
};
int main()
{
struct student student1 = {1001, "liming", 'M', 20, 92.5};/*定义结构体变量*/
struct student * p; /*定义指针变量指向结构体类型*/
p = &student1; /*使指针指向结构体变量*/
cout << "Number:" << p->num << endl; /*输出学生学号*/
cout << "Name:" << p->name << endl; /*输出学生姓名*/
cout << "Sex:" << p->sex << endl; /*输出学生性别*/
cout << "Age:" << p->age << endl; /*输出学生年龄*/
cout << "Score:" << p->score << endl; /*输出学生成绩*/
return 0;
}
/*
*在VC++6.0中运行的结果是:
*-----------------------------
*Number:1001
*Name:liming
*Sex:M
*Age:20
*Score:92.5
*Press any key to continue
*-----------------------------
*/
指向结构体变量的指针
最新推荐文章于 2021-05-19 02:54:17 发布