It is undefined behavior to try to overwrite a string literal. C99 §6.4.5/6:
If the program attempts to modify such
an array, the behavior is unde?ned.
This is restated in Appendix J.2 (undefined behavior).
If you instead do:
char p[] = "nyks";
you can allocate and initialize an automatic (stack) character array. In that case, it is perfectly fine to modify elements.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…