I have a little code that merge strcpy
array and pointer. I don't understand why the code displays "Good exam"
. I see that after the call to strcpy
, ptr
contains "lexam"
. So, can you explain when the value of a[]
changes?
char a[50] = "Good luck!";
char b[50] = { 'i','n',' ', 't','h','e',' ','e','x','a','m','\0' };
char* ptr = a + 5; cout << *ptr;
strcpy(ptr, &b[7]);
for (int i = 0; i < strlen(ptr); i++)
cout << ptr[i];
cout << a;