[0][1][2][3][4][5][6][7][8][9][10] [11]
a = [G][o][o][d][ ][l][u][c][k][!][]
b = [i][n][ ][t][h][e][ ][e][x][a][m] []
char* ptr = a + 5;
[0][1][2][3][4][5]
ptr = [l][u][c][k][!][]
[0][1][2][3][4]
&b[7] = [e][x][a][m][]
What you are doing is replacing the content that starts in b[7]
and overwriting whatever starts in ptr
(that is equivalent to a + 5
or &a[5]
).
Hence after strcpy you have:
[0][1][2][3][4][5]
ptr = [e][x][a][m][][]
Note that the place where the symbol !
was present is now a
because &b[7]
had length 4 while ptr
had length 5.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…