结构类型指针变量的使用实例
2014-11-17 02:27
211 查看
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { struct DateType { int year; int month; int day; }; struct StudentType { int num; char *name; char sex[3]; struct DateType birthday; float score; }; struct StudentType student; struct StudentType *pStudent; pStudent=&student; (*pStudent).num=10101; (*pStudent).name="µÂ»ªÁõ"; strcpy((*pStudent).sex,"ÄÐ"); (*pStudent).birthday.year=1962; (*pStudent).birthday.month=8; (*pStudent).birthday.day=18; (*pStudent).score=98.1; printf("ѧºÅ:%d\n",pStudent->num); printf("ÐÕÃû:%s\n",pStudent->name); printf("ÐÔ±ð:%s\n",pStudent->sex); printf("ÉúÈÕ:%dÄê,%dÔÂ,%dÈÕ\n",pStudent->birthday.year,pStudent->birthday.month,pStudent->birthday.day); printf("³É¼¨:%4.1lf\n",pStudent->score); system("PAUSE"); return 0; }在c语言中,pStudent—>num与(*pStudent).num等价,但是前者更加直观,希望读者多使用前者
相关文章推荐
- Blob字段类型的使用实例
- 类型实例的创建位置、托管对象在托管堆上的结构
- struts局部类型转换的使用和实例
- 在不能确定某一数据结构的结点是单一变量的情况下,结构的结点类型尽可能使用struct
- java 日期类型SimpledateFormat的使用实例
- 博客概念、类型、使用和结构
- Oracle数据库游标的类型及使用实例全解
- 类型实例的创建位置、托管对象在托管堆上的结构
- shell实例(八) ---指定变量类型:使用declare或typeset,随机数
- C#中结构数据类型的使用
- 一个使用泛型堆栈模块创建的两个容纳不同类型数据的实例
- 二十:构造器之二:实例构造器和结构(值类型)
- 使用Spring+hibernate透明操作blob(照片实例) 和clob类型
- ASP.NET AJAX中 复杂数据类型使用简单实例
- 类型实例的创建位置、托管对象在托管堆上的结构
- 急!delphi中variant能否和object类型转换。实例:在使用getpropvalue(range,'属性')时提示类型有错,如何解决?!!
- ASP.NET AJAX中 复杂数据类型使用简单实例
- Response.AddHeader使用实例收集 如何做下载,下载中文显示乱码怎么办 ContentType类型大全
- 尽可能使用泛型方法,除非需要将类型参数用于实例的字段
- 结构类型的使用,接口的使用,委托的使用