1. 程式人生 > >c結構體指針使用

c結構體指針使用

include lib TE 結果 main HA \n size 指針

 1 #include <stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 
 5 typedef struct _Date
 6 {
 7     unsigned int Year;
 8     unsigned int Month;
 9     unsigned int Day;
10 }Date;
11 
12 int main(int a,char** b)
13 {
14     Date * date1;
15     int back;
16     date1=malloc(sizeof
(Date)); 17 date1->Year=2018; 18 date1->Month=5; 19 date1->Day=31; 20 back=Change(date1); 21 printf("back is :%d\n",back); 22 printf("date is :%d,%d,%d\n",date1->Year,date1->Month,date1->Day); 23 date1->Year=0; 24 date1->Month=0; 25 date1->Day=0
; 26 free(date1); 27 return 0; 28 } 29 30 int Change (Date * date) 31 { 32 int back; 33 back=date->Year+date->Month+date->Day; 34 date->Year=1; 35 date->Month=2; 36 date->Day=3; 37 return back; 38 }

結果:

root:/opt/rwh# ./b
back is :2054
date is :1,2,3
root:
/opt/rwh#

c結構體指針使用