iOS 結構體struct就是這麼簡單 – iPhone手機開發 iPhone軟體開發教學課程

結構體的定義

// 結構體類型名 StudentScore

struct StudentScore {

int stuNo;

int stuMath;

int stuEnglish;

int stuChinese;

};

// 創建stu結構體信息

struct StudentScore st1 = {1, 98, 96, 87};

// 結構體值的調用

NSLog(@"st1:%d,%d,%d,%d",st1.stuNo,st1.stuMath,st1.stuEnglish,st1.stuChinese);

可以用typedef 來定義struct

// 使用typedef來定義結構體

typedef struct StudentScore2 { // 此處的StudentScore2可以直接刪除不寫

int stuNo;

int stuMath;

int stuEnglish;

int stuChinese;

} studentScore2;

studentScore2 st2 = {2, 95, 88, 98};

NSLog(@"st2:%d,%d,%d,%d",st2.stuNo,st2.stuMath,st2.stuEnglish,st2.stuChinese);

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *