【发布时间】:2015-11-05 01:17:35
【问题描述】:
例如,如果我要使用多个函数进行复杂计算,其中每个函数都完成部分工作,是否可以进行以下操作:
void initialize_equations() {
int t_constant;
time_t times;
double *current_time;
times= time(NULL);
t_constant = 365*24*60*60;
*current_time =times/t_constant;
printf("%Lf", current_time);
}
int year_day(time_t *crntT, int *constant) {
int year, month;
float year_l, month_l;
year_l=(¤t_time)/365; //trying to call crntT from previous function
year=year_l+1970; //time starts at 1970 therefore turned it from float to int then summed time
month=((year_l-year)*12)+1; // Month starts at Jan therefore +1
}
【问题讨论】:
-
为什么不简单地将其声明为全局变量?
-
@David 在代码中声明一个已经是热气腾腾的全局变量会使情况变得更糟。
-
你不要“调用”变量(除非它们是函数指针,但我们不要去那里)。您“访问”它们。不,你不能那样做。局部变量仅在调用其作用域的函数期间存在。
标签: c pointers time function-pointers