The exercise says \"Make a function with parameters two int arrays and k which is their size. The function should return another array (size k) where every element of it is the
This:
int i,g,a[g],b[g];
causes undefined behaviour. The value of g
is undefined upon initialisation, so therefore the length of a
and b
will be undefined.
You probably want something like:
int i, g;
int *a;
int *b; // Note: recommend declaring on separate lines, to avoid issues
scanf("%d", &g);
a = malloc(sizeof(*a) * g);
b = malloc(sizeof(*b) * g);
...
free(a);
free(b);