I have the following set of code not able to find why I am getting garbage value.My intention is to copy the number of byte as destination irrespective of source to make a generic copy for my application. But not getting the correct result.Is there any way to achieve this.
int main()
{
char x[6];
char *i="pra";
memset(&x,0,6); //Doing memset
memcpy(&x,i,6);
printf("%x %x %x %x %x %x",x[0],x[1],x[2],x[3],x[4],x[5]);
}
o/p:
70 72 61 0 25 78
We can see the output after 0 is garbage.But why it is comming and where it is comming. whey memset not working properly. Pleae help to get the cause of this concept.