typedef struct student 和 struct student 的区别
来源:互联网 发布:淘宝服装设计 编辑:程序博客网 时间:2024/05/29 08:43
{
int num;
struct student *next;
}student;
struct student
{
int num;
struct student *next;
};
第二个struct student是定义了一个student结构体,
第一个是用typedef 把 struct student 这个结构体类型名字重新定义为student,也就是说struct student和student表示同一个事物,都是一个类型的标识符,
比如 typedef int zhengshu; 就是你把整型int重命名为zhengshu,下面定义:int i; 和 zhengshu i; 两句就是等价的了
例程:
#define ListSize 10
typedef int DataType;
typedef struct{
DataType data【ListSize】;
int length;
}SeqList;
SeqList *L;
L->data =
L->length =
下面两个例程则是他们应用上的区别:
例1:不使用typedef,
//#include <apue.h>
#include <stdio.h>
#include <stdlib.h> //exit
#include <malloc.h>
#include <string.h>
struct pfilename{
char fn[20];
int fn_len;
char *pfn;
int pfn_len;
};
int
main(int argc, char **argv)
{
struct pfilename *pFhead;
pFhead = malloc(sizeof(struct pfilename));
strcpy(pFhead->fn,"iloveyou!");
pFhead->fn_len = strlen(pFhead->fn);
printf("pFhead->fn = %s,length = %d\n",(pFhead->fn),pFhead->fn_len);
//strcpy(pFhead->pfn,"iloveyou!");
pFhead->pfn = "iloveyou!!";
pFhead->pfn_len = strlen(pFhead->pfn);
printf("pFhead->pfn = %s,length = %d\n",(pFhead->pfn),pFhead->pfn_len);
return 0;
}
例2:使用typedef
#include <stdio.h>
#include <stdlib.h> //exit
#include <malloc.h>
#include <string.h>
typedef struct pfilename{
char fn[20];
int fn_len;
char *pfn;
int pfn_len;
}pfilename;
int
main(int argc, char **argv)
{
pfilename *pFhead;
pFhead = malloc(sizeof(pfilename));
strcpy(pFhead->fn,"iloveyou!");
pFhead->fn_len = strlen(pFhead->fn);
printf("pFhead->fn = %s,length = %d\n",(pFhead->fn),pFhead->fn_len);
//strcpy(pFhead->pfn,"iloveyou!");
pFhead->pfn = "iloveyou!!";
pFhead->pfn_len = strlen(pFhead->pfn);
printf("pFhead->pfn = %s,length = %d\n",(pFhead->pfn),pFhead->pfn_len);
return 0;
}
- typedef struct student 和 struct student 的区别
- typedef struct和struct的区别
- typedef struct和struct的区别
- struct和typedef struct的区别
- struct和typedef struct的区别
- typedef struct和struct的区别
- struct和typedef struct的区别
- typedef struct 和 struct 的区别
- struct和typedef struct的区别
- struct和typedef struct的区别
- struct和typedef struct的区别
- 【VC】typedef struct 和 struct 的区别
- struct 和typedef struct的区别
- struct和typedef struct的区别
- struct和typedef struct的区别
- typedef struct 和 struct的区别
- struct和typedef struct的区别
- typedef struct和struct的区别
- TOJ-2191-Golden Flower
- Web App适配不同屏幕的几点建议
- 黑马程序员_权限控制的算法
- dede的list标签支持weight排序
- mysql如何添加用户
- typedef struct student 和 struct student 的区别
- vim cscope 插件使用
- Unique Paths
- java动态代理(JDK和cglib)
- Configuration file: / etc / hostapd / hostapd.conf nl80211: 'nl80211' generic netlink not found
- 蓝桥杯 算法训练 安慰奶牛
- 最值钱的30句话,总有一句让你有收获
- Oracle-SQL-group by-报错:不是单组分组函数
- 泛型编程 实例 阶乘