here is the code that takes two arrays(with no two elements of array same) as input and outputs a third array which is the union of the two arrays. i.e the third array contains all elements of 1st array and non repeating elements of second array.
ex: a={1,2,3,4}
b={4,5,6} , then it should return
c={1,2,3,4,5,6}
I have marked the errors in the code. please help.
i think my concept about pointers and arrays is not very clear.
when i made the statement return c in uni function, i thought that it is returning nothing but the pointer to the base address of c and that it would be appropriate to store this value in array name c( which is again a pointer to the base address of c).
can you please help me understand the concept. and i would appreciate if you could just show me what changes i should make in my code.
int uni( int c[], int a[], int b[], int n1, int n2 )
{
int k = 0;
for( ; k < n1; k++ ) c[k] = a[k];
for( int i = 0; i < n2; i++ )
{
int j = 0;
for( ; j < n1 && a[j] != b[i]; j++ );
if ( j == n1 ) c[k++] = b[i];
}
return ( k );
}