例题9.9
来源:互联网 发布:mac os最新系统 编辑:程序博客网 时间:2024/04/27 12:06
#include<stdio.h>#include<stdlib.h>#define LEN sizeof(struct Student)struct Student{long num;float score;struct Student*next;} ;int n;struct Student*creat(){struct Student*head;struct Student*p1,*p2;n=0;//p1=p2=(struct Student*)malloc(LEN);p1=p2=(struct Student*)malloc (sizeof(struct Student));scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;//p1=(struct Student*)malloc(LEN);p1=(struct Student*)malloc (sizeof(struct Student)) ;scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return (head);}int main(){struct Student*pt;pt=creat();printf("\nnum:%ld\nscore:%5.1f\n",pt->num,pt->score);return 0;}
创建一个链表的时候为什么开辟节点空间的时候会是p1=(struct Student*)malloc (sizeof(struct Student)) ;可以成功,但是用宏定义的p1=(struct Student*)malloc (LEN)就不对呢 ;
- 例题9.9
- 例题
- 例题
- 例题
- 例题
- 面试例题
- C++ 例题
- 面试例题
- 反射例题
- acm例题
- jdbc例题
- C++例题
- C++例题
- C++例题
- 例题分析
- 各种例题
- 例题6.3
- Continue例题
- STL面试题
- 逻辑和物理数据模型的区别
- WebLogic优化大全
- 块设备、字符设备
- 头文件的用途和结构
- 例题9.9
- 配置ORACLE用户的ssh authorized keys
- GCC出现warning: integer constant is too large for 'long' type"
- 人生感悟:人生想成功必须要领悟的9个词
- 解决VS2010速度慢的问题
- Hadoop 新 MapReduce 框架 Yarn 详解【转载】
- STL面试题二
- [3月18日的脚本] 在SharePoint Server 2010中热启动应用程序
- 求任意一整数的各位数和