udragu
April 14th, 2016, 12:01 PM
Hello all. I've tried to study C11.
I've some stuck;)
there is a code
double *get_vect(int n)
{
double *indi = malloc(n*sizeof(double));
return indi;
}
int main(int argc, char* argv[])
{
int num=1000;
double *res = get_vect(num);
return 0;
}
Is it necessary to call free() every time when I use malloc(), even inside main()?
And if it's necessary, may be, is there a better way to pass some extra ¶m for result array?
What's the principal difference between return pointer on heap and void get_vect(int n,&res){....}. What's better and When?
Thanks all. Sorry if it's look like homework).
I've some stuck;)
there is a code
double *get_vect(int n)
{
double *indi = malloc(n*sizeof(double));
return indi;
}
int main(int argc, char* argv[])
{
int num=1000;
double *res = get_vect(num);
return 0;
}
Is it necessary to call free() every time when I use malloc(), even inside main()?
And if it's necessary, may be, is there a better way to pass some extra ¶m for result array?
What's the principal difference between return pointer on heap and void get_vect(int n,&res){....}. What's better and When?
Thanks all. Sorry if it's look like homework).