struct用法
来源:互联网 发布:鼠标垫品牌 知乎 编辑:程序博客网 时间:2024/05/22 03:08
1) struct{ int x; int y; }test1; 定义了 结构 test1,test1.x 和 test1.y 可以在语句里用了。(2) struct test {int x; int y; }test1; 定义了 结构 test1,test1.x 和 test1.y 可以在语句里用了。与 1 比,1里面省写 了 test(3) typedef struct test {int x; int y; }text1,text2; 只说了 这种结构 的(类型)别名 叫 text1 或叫 text2真正在语句里用,还要写:text1 hwh;然后好用 hwh.x, hwh.y或写 text2 hwh1;然后好用 hwh.x, hwh.y(4)typedef struct {int x; int y; }test1;同 (3)一样,真正在语句里用,还要 写:test1 hwh;才能用 hwh.x 和 hwh.y
(5)超高端用法
typedef struct list *list_p; //首先定义了一个结构体list,在这里要把struct list看成是一体了,继续分析
//在这里,list_p是一个结构体指针,struct list *就等同于list_p,这样做是可以在下面互相替换
//在定义结构list之前,定义了一个指向该结构的指针list_p,C语言允许定义指向不存在的类型的指针。
typedef struct list{
char a[3];
list_p link;//结构体自引用,这句话等同于struct list * link;。link是一个指向结构体的的指针
};
//在定义了结构list之后,就可以建立一个新表,用list_p ptr = Null; 完成。
list_p ptr = Null; //存在一个名为ptr的新表ptr包含表的起始地址
ptr = (list_p) malloc(sizeof(list)); //
//e->name 等同与(*e).name//e是指针
strcpy(ptr->a, "bat");
ptr->link = NULL;
-----
完整代码:
#include<stdio.h>#include<stdlib.h>#include<string.h>main(){typedef struct list_node *list_pointer;typedef struct list_node{char data[4];list_pointer link;};list_pointer ptr = NULL;ptr = (list_pointer)malloc(sizeof(list_node));strcpy(ptr->data, "bat");ptr->link = NULL;printf("%s\n",ptr->data);}
-----
#include<stdio.h>#include<stdlib.h>void main(){typedef struct list_node *list_pointer;typedef struct list_node{int data;list_pointer link;};list_pointer first = NULL, second = NULL;first = (list_pointer)malloc(sizeof(list_node));second = (list_pointer)malloc(sizeof(list_node));first->data = 10;first->link = second;second->data = 20;second->link = NULL;printf("%d\n",first->data);printf("%d\n",first->link->data);}
- struct 用法
- struct用法
- struct用法
- typedef struct 用法详解
- typedef struct的用法
- typedef struct用法详解
- 结构体(struct) 用法
- typedef struct 用法详解
- typedef struct 用法详解
- typedef struct 用法详解
- typedef struct 用法详解
- typedef struct 用法详解
- typedef struct的用法
- struct stat 的用法
- typedef struct 用法详解
- struct用法深入探索
- struct stat 的用法
- struct 用法的示例
- java(TM) Platform SE binary已停止工作
- 目标检测的图像特征提取之(二)LBP特征
- BTrace使用总结
- 飞鸽沟通软件2013最新版下载
- matlab quantization 1 ~ 8 層
- struct用法
- 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该...
- Qt phonon多媒体框架
- 去除中文乱码
- 目标检测的图像特征提取之(三)Haar特征
- hdoj 1166 线段树
- JVM(Java虚拟机)优化大全和案例实战
- 二分图最大匹配--poj2536
- php利用内置的svn函数实现的svn版本号的提交、更新、删除、恢复等功能