Yes you can, but you need to allocate memory for resultsomewhere.
Basically, you can either allocate memory inside vec_subtractionor outside vec_subtraction, if you choose the outside, you can do it statically or dynamically.
If you are going to highlight inside:
double *vec_subtraction (char *a, char *b, int n) {
double *result = malloc(sizeof(double)*n);
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
return result;
}
and basically:
double *vec;
vec = vec_subtraction(a, b, n);
free(vec);
Do not forget the freeresult of the call vec_subtractionafter a while.
, :
void vec_subtraction (char *a, char *b, int n, double *result) {
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
}
:
// choose one of:
// double *vec = malloc(sizeof(double)*n);
// double vec[10]; // where 10= n.
vec_subtraction(a, b, n, vec);
// if you used *vec = malloc... remember to call free(vec).