From ISO/IEC 9899:TC3 (c99)
7.21.2.3 The strcpy function
Synopsis
1
#include <string.h>
char *strncpy(char * restrict s1,
const char * restrict s2,
size_t n);
Description
2 The strcpy function copies the string pointed to by s2 (including the terminating null
character) into the array pointed to by s1. If copying takes place between objects that
overlap, the behavior is undefined.
So what you are doing is simply undefined behaving ;)
You can also see the ANNEX J.2
Stating cases of undefined behavior with a note how to prevent:
The behavior is undefined in the following circumstances:
[...]
—An attempt is made to copy an object to an overlapping object by use of a library
function, other than as explicitly allowed (e.g., memmove) (clause 7).
e
. – Hammocksrc
decays to a pointer to the first element of the arraysrc
.&src[1]
is a pointer to the second element of the array. As the source-string is not of length 0, they obviously overlap. – Benavideschar dest[]="123456";
" and do "strcpy(src, &dest[1]);
" – Kayne