Ric*_*III 1 c arrays free pointers calloc
在C中,如何重置给定指针以使数组中的所有值都是指定值?最好使用for循环,还是有一个函数可以用来将数组中的所有值都设置为0.
我的代码目前是这样的:
int main()
{
double *my_values = calloc(10, sizeof(double));
do_something_with_values(my_values);
free(my_values);
my_values = calloc(10, sizeof(double));
do_something_else_with_values(my_values);
free(my_values);
}
Run Code Online (Sandbox Code Playgroud)
这(对我来说)看起来很hacky,我该如何改进这段代码呢?