c语言函数必须先定义后使用吗,求助,函数在其他函数中使用时要先声明后调用,这个没声明就用了... |
您所在的位置:网站首页 › c程序中变量必须先定义后使用函数吗对吗 › c语言函数必须先定义后使用吗,求助,函数在其他函数中使用时要先声明后调用,这个没声明就用了... |
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 如题,程序如下: #include #include //malloc,calloc,free,realloc头文件 #define LEN sizeof(struct Student) struct Student {long num; float score; struct Student *next; }; int n; //到这里都是一些初始定义 struct Student *creat(void) //这里开始定义了一个函数creat { struct Student *head,*p1,*p2; n=0; p1=p2=(struct Student*)malloc(LEN); scanf("%ld,%f",&p1->num,&p1->score); head=NULL; while(p1->num!=0) { n=n+1; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct Student*)malloc(LEN); scanf("%ld,%f",&p1->num,&p1->score); } p2->next=NULL; return (head); } //到这里creat函数定义部分结束一般函数定义都写后面这个写前面了,区别? int main() //这里开始main函数 { struct Student *pt; pt=creat(); //不懂在这点,没声明,直接就调用了??编译运行没错误 printf("\nnum:%ld\nscore:%5.1f\n",pt->num,pt->score); return 0; } 函数调用,涉及到动态链表就不用声明了么?? |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |