A
amjadcsu
Hello.
I am trying to learn concept of pointers in C
I wrote a simple int copy program which basically copies the two int
arrays
char *mystrcpy( int *source, int *dest, int no)
{
printf("the first element of char is %d \n", *source);
int i;
for (i=0;i<4;i++)
{
*dest++ =*source++;
}
return dest;
}
int a[5]={2,3,4,5};
int i,j;
//char *ptrA;
//char *ptrB;
int b[5];
ptrA=a;
ptrB=b;
ptrB=mystrcpy (ptrA ,ptrB,3);
for (i=0;i<4;i++)
{
printf("the b array is %d \n",b);
}
So i would expect the output of this program to be
the b array is 2
the b array is 3
the b array is 4
the b array is 5
but i get the following output
the b array is 134518416
the b array is 3
the b array is 4
the b array is 5
Can someone tell me why the first element is messed up
thanks
I am trying to learn concept of pointers in C
I wrote a simple int copy program which basically copies the two int
arrays
char *mystrcpy( int *source, int *dest, int no)
{
printf("the first element of char is %d \n", *source);
int i;
for (i=0;i<4;i++)
{
*dest++ =*source++;
}
return dest;
}
int a[5]={2,3,4,5};
int i,j;
//char *ptrA;
//char *ptrB;
int b[5];
ptrA=a;
ptrB=b;
ptrB=mystrcpy (ptrA ,ptrB,3);
for (i=0;i<4;i++)
{
printf("the b array is %d \n",b);
}
So i would expect the output of this program to be
the b array is 2
the b array is 3
the b array is 4
the b array is 5
but i get the following output
the b array is 134518416
the b array is 3
the b array is 4
the b array is 5
Can someone tell me why the first element is messed up
thanks