Can I do something like this? Will this work?
double *vec_subtraction (char *a, char *b, int n)
{
double *result;
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
return result;
}
and then in main:
double *vec=vec_substraction(a, b, n);
for(i=1; i<n; i++)
printf("%d", vec[i]);
a and b are vectors with the same number of elements, n is number of elements.
Yes you can, but you need to allocate memory for
resultsomewhere.Basically, you can either allocate the memory inside
vec_subtractionor outsidevec_subtraction, if you allocate outside you can do this statically or dynamically.If you’re going to allocate inside:
and in main:
Don’t forget to
freethe result of the call tovec_subtractionsometime later.If you’re going to allocate outside you need to pass in a pointer to the memory:
in main: