iOS 結構體struct就是這么簡單

結構體的定義

// 結構體類型名 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);

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。