Here is a solution that does not use pointers and gets to the heart of the issue, element positions are not the same in the second loop
Code:
/*Merge2Arraystoa3rd.c*/
#include<stdio.h>
int main ()
{
int i;
int x[] = { 1, 9, 3, 4 };
int y[] = { 7, 2, 5, 8, 6 };
// int z[9];
int z[10]; // a C string must have one extra element for the "\0" //See Strings in C - GeeksforGeeks
for (i = 0; i <4; i++)
{
//&z[i];
z[i] = x[i]; // each element in array x will copy into the same array element position in z
} // but this is not the same in the next iteration
for (i = 0; i <5; i++) // Element position 0 in y is equal to element position 4 in z
{
//&z[i];
z[i+4] = y[i];
}
for (i = 0; i <9; i++)
{
printf("z[%d] = %d\n", i, z[i]);
}
return 0;
}[