How to copy a string using a pointer

前端 未结 7 1531
野趣味
野趣味 2020-12-15 21:05

Here\'s a program I wrote to copy a string constant.

When the program is run it crashes. Why is this happening ?

#include 

char *alph         


        
7条回答
  •  执念已碎
    2020-12-15 21:15

    You can directly do the below code:

    char *alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char *l = alpha;
    

    If your code was below:

    const char *alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const char *l = alpha;
    

    :)

提交回复
热议问题