- 论坛徽章:
- 0
|
我知道传值不可以修改实参,传址可以修改实参,就如:
- struct STRU
- {
- int stru_i_count ;
- char stru_c ;
- } ;
- void change_struct(struct STRU * stru , char c , int count int test)
- {
- stru->stru_c = c ; // 传址,可以被改变
- stru->stru_i_count = count ;
- test = 100 ; // 传值,不能被改变
- }
- int main(int argc , char * argv[])
- {
- struct STRU * st1 ;
- int i = 0 ;
- st1 = (struct STRU *)malloc(sizeof(struct STRU) * 1) ;
- memset(st1 , 0 , sizeof(struct STRU)) ;
- change_struct(st1 , 'A' , 100 , i) ;
- printf("%c , %dni=%dn" , st1->stru_c , st1->stru_i_count , i) ;
- free(st1) ;
-
- }
复制代码
但就为何在 :
- int lib_sec2tm(long sec , struct tm * m) //
- {
- time_t timep ;
- timep = (time_t)sec ;
- m = localtime(&timep); //
- return 0 ;
- }
- int get_sec2tm(long isec)
- {
- struct tm * t = NULL ;
- char * str_time = NULL ;
- t = (struct tm *)malloc(sizeof(struct tm)) ;
- memset(t , 0 , sizeof(struct tm)) ;
- str_time = (char *)malloc(sizeof(char) * 100 + 1) ;
- memset(str_time , 0 , 100) ;
- lib_sec2tm(isec , t) ; //
- strftime(str_time,100,"%Y-%m-%d %H:%M:%S , %sn",t);
- printf("Sec is %ld , convert to time %sn", isec , str_time); // 打印出 1900-11-00 ...
- // 应该是 2005-11-13 ...
- free(t) ;
- free(str_time) ;
-
- }
- 不能修改 t 的值呢 ? 两个程序中传的都是结构的地址啊 , 为什么呢 ?
复制代码 |
|