POINTER TO STRUCTURE指向结构的指针

上传人:油条 文档编号:20309091 上传时间:2017-11-21 格式:DOCX 页数:3 大小:14.12KB
返回 下载 相关 举报
POINTER TO STRUCTURE指向结构的指针_第1页
第1页 / 共3页
POINTER TO STRUCTURE指向结构的指针_第2页
第2页 / 共3页
POINTER TO STRUCTURE指向结构的指针_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《POINTER TO STRUCTURE指向结构的指针》由会员分享,可在线阅读,更多相关《POINTER TO STRUCTURE指向结构的指针(3页珍藏版)》请在金锄头文库上搜索。

1、POINTER TO STRUCTUREWhen a structure is defined, part of its definition is the type of the structure. In the example under STRUCTURE in this section, the structure type is my_struct. There may be many variables that are defined as being of type my_struct, for example var1, var2 may be defined as bei

2、ng of type my_struct. It is often useful to have a variable that can point to different structure variables (of the same type) at different times. This is handled by defining a variable of type Pointer To Structure. The pointer to structure variable is defined by using the symbol. The pointer to str

3、ucture variable is assigned to a structure variable by using the & symbol. EXAMPLE:In the following example, a structure of type my_struct is defined, with two members.Two variables var1 and var2 are defined which are structures of type my_struct.A variable var_struc is defined which is a pointer to

4、 structure variable which points to structures of type my_struc. The members of var1 and var2 have values assigned to them. Note the use of the member pointer (.) in assignments. Then var_struc is assigned to point to var1 using the & symbol. The values of the members of the structure pointed to by

5、var_struc are written out. Note that the symbol (-) replaces the use of the member pointer (.) when accessing members for pointer to structure variables. - definition of structure -structure my_struct- members of structureii : integerrr : realendstructure- variable definitions -var- variables define

6、d as being of type my_structvar1,var2 : my_struct- variable defined as being a pointer to structures- of type my_structvar_struc : my_structprocedure struct_demo()begin- assign values to the variables for their members- note the use of the period var1.ii = 100var2.ii = 200var1.rr = 1.1 var2.rr = 2.2

7、- set the structure pointer to point to the structure- var1 note the use of &var_struc = &var1- write out the values of the members of var_struc- note the use of -write (var_struc-ii, ,var_struc-rr,cr)- set the structure pointer to point to the structure- var2 note the use of &var_struc = &var2- wri

8、te out the values of the members of var_struc- note the use of -write (var_struc-ii, ,var_struc-rr,cr)end 指向结构 当一个结构的定义,其定义的一部分是该结构的型。在本节下结构的例子中,结构类型为MY_STRUCT。有可能是,被定义的类型是 MY_STRUCT,例如 var1 的许多变量,VAR2 可以被定义为类型 MY_STRUCT 的。它是非常有用的是具有可在不同的时间点,以不同的结构变量(同一类型的)的一个变量。这是通过定义类型的指针变量来构造处理。 以结构体变量的指针是通过使用符号定

9、义。以结构体变量的指针是通过使用 符号分配给一个结构体变量。 示例: 在下面的例子中,类型 MY_STRUCT 的结构定义,有两个成员。 两个变量 var1 和定义它的类型是 MY_STRUCT 的结构。 变量 var_struc 定义它是一个指向结构体变量,它指向型 my_struc 的结构。 var1 和成员都分配给他们的价值观。注意:在分配使用的成员指针()的。然后 var_struc 被分配到使用点的符号 VAR1。结构的成员的值指向 var_struc 都写了出来。需要注意的是符号 - () ()取代了使用该成员指针访问成员指针,结构体变量的时候。 -结构的定义- 结构 MY_STR

10、UCT - 结构的成员 二:整数 RR:实 endstructure -变量定义 - 变种 - 定义为类型 MY_STRUCT 变量 VAR1,VAR2:MY_STRUCT - 变量定义为一个指向结构 - 类型 MY_STRUCT 的 var_struc: MY_STRUCT 程序 struct_demo() 开始 - 赋值给变量及其成员 - 注意使用期限 var1.ii=100 var2.ii=200 var1.rr=1.1 var2.rr=2.2 - 设置结构指针以指向结构 - VAR1 注意使用 var_struc=VAR1 - 写出来 var_struc 的成员的值 - 注意使用 - 写(var_struc - 二,var_struc - RR,CR) - 设置结构指针以指向结构 - VAR2 注意使用 var_struc=VAR2 - 写出来 var_struc 的成员的值 - 注意使用 - 写(var_struc - 二,var_struc - RR,CR) 结束

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号