I tried to print out the return value of strcpy() and it gave me an "Access violation reading location" exception.
char ind[15];
printf("%s\n", strcpy(ind, "source text"));
or with debugging statements:
char* ins = "source text";
char* dst;
dst = strcpy(ind, ins);
printf("dst = %s", dst);
Visual Studio showed that ind = 0x00000024ec71f448
"source text"
whereas dst = 0xffffffffec71f448
<Error reading characters of string.> <Unable to read memory> .
Shouldn't dst = ind? pointing to the same address?
Great answers, all!
Without <string.h>, it defaulted to "int strcpy()" when I hovered my mouse over strcpy. After including <string.h>, it showed "char *strcpy()".
About the address values, my PC runs a 64-bit Windows 10. Since "int" is typically 32 bit on most 64 bit platforms, dst is capped at 32-bit with bogus upper 32-bit.
One catch is that in order to use Visual Studio to build, you have to add #define _CRT_SECURE_NO_WARNINGS above all #include .h's to avoid compiler errors. The reason is that VS recommends using errno_t strcpy_s(...) instead of strcpy(). But strcpy_s() will then return a value of if successful. That makes our dst = 0, a NULL pointer, and the #define helps get around it.
After all the fixes, dst = ind = 0x000000249d8ff528 "source test". Thanks.