C語言提高38 結構體套一級指標

2021-07-09 08:13:01 字數 808 閱讀 7478

//結構體陣列  3  輸入老師年齡  排序

#include#include#include#includetypedef struct teacher

teacher;

void printfteacher(teacher*array, int num)

}void sortteacher(teacher*array, int num)

} }}int createteacher(teacher**pt, int num)

memset(tmp, 0, sizeof(teacher)*num);//剛分配完後 立馬初始化

for (i = 0;i < num;i++)

//pt二級指標 *pt就是一級指標 也就是parray的位址

*pt = tmp;//二級指標 形參 去間接修改實參的值

return 0;

}void freeteacher(teacher*p, int num)

for (int i = 0; i < num; i++) }

}void main41()

for (i = 0; i < num; i++)

printfteacher(parray, num);

sortteacher(parray, num);

printf("排序之後\n");

printfteacher(parray, num);

printf("hehehe\n");

system("pause");

return;

}

C語言提高40 結構體套一級指標和二級指標

結構體陣列 3 輸入老師年齡 排序 include include include includetypedef struct teacher teacher void printfteacher teacher array,int num void sortteacher teacher arra...

c語言 結構體巢狀一級指標

這裡用支了二級指標 void test 執行 name name 1 age 100name name 2 age 101name name 3 age 102name name 1的記憶體被釋放 name name 2的記憶體被釋放 name name 3的記憶體被釋放 分配記憶體 struct ...

結構體中套一級指標

define crt secure no warnings include include include typedef struct teacher teacher 陣列做函式引數會退化為指標 void printteacher teacher array,int num void sortte...