#include<stdio.h> #include<string.h> int main() {struct Student { long num; char name[22]; char sex; float score; }; struct Student stu_1;//定義struct student類型的變量stu1 struct Student *p;//定義指向struct student類型數據的指針變量p p=&stu_1;//p指向stu1 stu_1.num=10101;//對結構體的變量成員賦值 strcpy(stu_1.name,"LiLin");//用字符串復制函數給stu1.name賦值 stu_1.sex='M'; stu_1.score=89.5; printf("No.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",stu_1.num,stu_1.name,stu_1.sex,stu_1.score);//輸出結果 printf("No.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",(*p).num,(*p).name,(*p).sex,(*p).score); return 0; }
No.:10101
name:LiLin
sex:M
score: 89.5
No.:10101
name:LiLin
sex:M
score: 89.5
--------------------------------
Process exited after 0.238 seconds with return value 0
請按任意鍵繼續. . .
