mfc结构体指针、结构体数组指针
来源:互联网 发布:教武术的软件 编辑:程序博客网 时间:2024/06/14 09:16
代码说明一切。
1 #include <stdio.h> // 预编译处理命令
2 #include <string.h>
3
4 struct student{
5 long num;
6 char name[20];
7 };
8
9 int main()
10 {
11 struct student stu;
12 struct student * p;
13 stu.num=12;
14 // 为什么这里直接进行赋值会出现错误呢?
15
16 // stu.name="nihao"; 赋值只能在初始化之后
17 // 比如像是这样,char str[]="yuanhui";
18
19 strcpy(stu.name, "nihao");
20 p=&stu;
21
22 // 输出的时候一定要是先(*p) 表示指向结构体的变量,后面的.表示结构体变量中的成员
23 printf("%d\n", (*p).num); // 12
24 printf("\n"); // \ 转移字符
25
26 // 也可以这样表示
27 printf("%d\n", p->num); // 12
28
29 // ->表示的是指向运算符
30 printf("%d\n", p->num++); // 12, 是先输出了他的值,再加上1
31 printf("%d\n", ++p->num); // 14, num的值已经是13了,先加上1再去计算它的值
32
33 return 0;
34 }
// 结构体数组指针
1 #include <stdio.h>
2 #include <string.h>
3
4 struct student{
5 long num;
6 char name[20];
7 }stu[3]={102,"yuan",103,"hui",104,"nihao"};
8
9 int main()
10 {
11 struct student * p;
12
13 // 指针的初始值指向stu的首地址,也就是第一个结构体
14 // 逐渐增加,指向的是下一个结构体指针
15
16 for(p=stu;p<stu+3;p++){
17 printf("%d %s\n", p->num, p->name);
18 }
19
20
21 // ->表示的是指向运算符
22 return 0;
23 }
- mfc结构体指针、结构体数组指针
- 结构体数组指针
- 结构体指针数组
- 结构体&结构体指针&结构体指针数组
- 结构体指针访问结构体数组
- 结构体数组和结构体指针
- 结构体指针和结构体数组
- 数组、结构体、指针1
- 数组、结构体、指针2
- 数组、结构体、指针3
- 数组、结构体、指针4
- 结构体指针和数组
- 数据结构 - 指针,数组,结构体
- 结构体数组指针memset
- 基本指针,数组,结构体
- 结构体数组与指针
- 结构体,数组,指针,地址
- 指针结构体_数组指针结构体_指针数组结构
- java.lang.Error:Properties init:Could not determine current working directory
- 改变MyEclipse的默认编码方式
- static 修饰的成员变量
- Validate Binary Search Tree
- 走进小作坊(二十一)----合格的员工这样工作
- mfc结构体指针、结构体数组指针
- POJ1753解题报告(位压缩+DFS/BFS)
- A Simple Problem with Integers+hdu+树状数组
- G3D游戏引擎——编译
- lecture10-模型的结合与全贝叶斯学习
- DACL, NULL or not NULL
- Overload和Override的区别
- lua入门学习
- F