I'm currently going over pointers and to further my understanding I'm trying to concatenate two numerical arrays into one using pointers. The code can be seen below.
#include <stdio.h>
void concat(int **pa,int **pb,int **pc)
{
pc[0]=*pb;
pc[3]=*pa;
}
int main()
{ int i, array_a[3]={2,4,6},array_b[3]={1,3,5},array_c[6];
int *p_a=array_a;
int *p_b=array_b;
int *p_c=array_c;
concat(&p_a,&p_b,&p_c);
for(i=0;i<6;i++)
{
printf("array_c[%d]=%d\n",i,p_c[i]);
}
return 0;
}
And here is the output.
array_c[0]=1
array_c[1]=3
array_c[2]=5
array_c[3]=0
array_c[4]=2
array_c[5]=4
Press any key to continue.
So it seems to work for the first operation in the function, however the second operation does not fully work. I would've thought this would work. I'm slightly confused with this simple task.
I have done the concatenation using pointers and for loops earlier today and it worked, but I thought I would try using this method using the call by reference and double pointers.
Any help would be greatly appreciated, thanks.