sizeof, strlen, 指標和數組作為函數參數

來源:互聯網
上載者:User

typedef struct st_test<br />{<br />int id;<br />char *pName;<br />char class[10];<br />}Student;</p><p>void fn(Student *pStud) {<br />pStud->id = 10;<br />pStud->pName = "Tom Simith";<br />strcpy(pStud->class, "Class 1");<br />printf("sizeof(pStud) = %d /n", sizeof(pStud));// sizeof(pStud) = 4<br />printf("sizeof(pStud->id) = %d /n", sizeof(pStud->id));// sizeof(pStud->id) = 4<br />printf("id:%d/n", pStud->id);// id:10<br />printf("sizeof(pStud->pName) = %d /n", sizeof(pStud->pName));// sizeof(pStud->pName) = 4<br />printf("strlen(pStud->pName) = %d /n", strlen(pStud->pName));// strlen(pStud->pName) = 10<br />printf("Name:%s/n", pStud->pName);// Name:Tom Simith<br />printf("sizeof(pStud->class) = %d /n", sizeof(pStud->class));// sizeof(pStud->class) = 10<br />printf("strlen(pStud->class) = %d /n", strlen(pStud->class));// strlen(pStud->class) = 7<br />printf("class:%s/n", pStud->class);// class:Class 1<br />}</p><p>void fnArray(char arr[]) {<br />printf("arr:%s/n", arr);// arr:Hello<br />printf("sizeof(arr) = %d /n", sizeof(arr));// sizeof(arr) = 4The length of pointer<br />printf("strlen(arr) = %d /n", strlen(arr));// strlen(arr) = 5The length of array<br />}</p><p>int main(int argc, char **argv)<br />{</p><p>Student stud;<br />fn(&stud);</p><p>fnArray("Hello");<br /> return 0;<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.