Um. That's confused code!
You create two char arrays:
char ch[] = "Hello";
char pa[10];
And by the C language definition, the name of an array is a pointer to the first element, so both
ch
and
pa
are pointers to
char
values.
Then you create a char pointer and set it to one of them:
char *ptr;
ptr=ch;
But then you overwrite one of the array pointers with the other:
pa=ptr;
Which means that you no longer have anything which can access the second array data!
If you are trying to copy data from one array to the other using pointers, then you need to create two new pointers so that you can "walk" them through the arrays:
char inp[] = "Hello World!";
char out[13];
char *pinp = inp;
char *pout = out;
for (int i = 0; i < 13; i++)
{
*pout++ = *pinp++;
}
printf("%s\n", out);