結構體指標做函數參數

來源:互聯網
上載者:User

標籤:

 

 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5  6 //定義一個結構體 7 //定義一個資料類型。固定記憶體大小的別名,還沒有分配記憶體 8 /*struct Teacher 9 {10     char name[5];11     int age;12 };*/13 typedef struct Teacher14 {15     char name[64];16     int age;17     int id;18 }Teacher;19 20 21 struct Student22 {23     char name[64];24     int age;25 }s1,s2;//定義類型 同時定義變數26 27 struct28 {29     char name[64];30     int age;31 32 }s3, s4;    //匿名型別 定義變數33 34 //初始設定變數的三種方法35 //定義變數 然後初始化36 //37 Teacher t7 = { "aaaaa", 18, 01 };    //全域38 struct Student239 {40     char name[64];41     int age;42 }s5 = { "names", 21 };43 44 struct45 {46     char name[64];47     int age;48 49 }s6 = { "names", 30 };50 51 52 void copyTeacher01(Teacher *to,Teacher *from)53 {54     *to = *from;55 }56 int main()57 {58     Teacher t1 = { "aaaa", 32, 01 };59     Teacher t2;60     t2 = t1;    //=號操作下 編譯器的行為61                 //C編譯器提供簡單的賦值操作62     Teacher t3;63     printf("t2.name:%s\n",t2.name );64     printf("t2.age:%d\n", t2.age);65     copyTeacher01(&t3, &t1);66     printf("t2.name:%s\n", t3.name);67     printf("t2.age:%d\n", t3.age);68     system("pause");69     return 0;70 }

 

結構體指標做函數參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.