亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么會出現程序崩潰?!!

為什么會出現程序崩潰???!

C PHP
暮色呼如 2023-03-16 17:13:21
#include <stdio.h>#include <stdlib.h>#include <time.h>typedef struct Node{int data;struct Node *next;}Node, *pt_Node;//初始化生成頭結點static int InitList(pt_Node L)//為什么是*L才正確???就這里也不懂{L = (pt_Node)malloc(sizeof(Node));if (!L){return -1;}L->next = NULL;return 0;}/*統計鏈表的長度*/static int ListLenth(pt_Node L){int i = 0;pt_Node p = L->next;while (p){i++;p = p->next;}return i;}int main(void){int lenth;pt_Node link;//不能是*link?為什么InitList(link);lenth = ListLenth(link);printf("the lenth is %d", lenth);return 0;}
查看完整描述

1 回答

?
手掌心

TA貢獻1942條經驗 獲得超3個贊

這個代碼的流程 ,是在主函數中定義一個頭節點link
然后通過函數InitList來給頭節點賦值。 
既然要給link賦值,就需要參數是link的指針類型,否則無法傳回主函數。
于是需要定義成
static int InitList(pt_Node *L)
同時在函數中給*L賦值。 
調用的時候 用InitList(&link);

查看完整回答
反對 回復 2023-03-18
  • 1 回答
  • 0 關注
  • 86 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號