I was trying a basic program to copy elements form one array to another. The source array is having more elements. While copying elements from source to destination i only copy few elements from source array.
My source array contains some hex value.
As i am printing the destination array in hex form the last element is different. i.e that elements unknowingly adds up ffffff
Here is the sample program
void String_Copy(char *src, char *dest, int length)
{
for (int i=0; i<length; i++)
{
dest[i] = src[i];
}
}
int main(void)
{
char firstStr[] = {0x01,0x03,0x02,0x13,0x88,0xB5,0x12};
char secStr[5];
String_Copy(firstStr,secStr,5);
for (int i=0;i<5;i++)
{
printf("%02x ",secStr[i]);
}
}
Here i want to copy only five elements and print the output.
Expected Output: 01 03 02 13 88
Getting Output: 01 03 02 13 ffffff88
Where are these ffffff
are coming from???
What is happening behind the scene?????
Thanks in advance