Why do we need strdup()?

前端 未结 5 1834
花落未央
花落未央 2021-02-20 07:24

While I was working on an assignment, I came to know that we should not use assignments such as :

 char *s=\"HELLO WORLD\";

Programs using such

5条回答
  •  有刺的猬
    2021-02-20 08:28

    This is a problem in C. Although string literals are char * you can't modify them, so they are effectively const char*.

    If you are using gcc, you can use -Wwrite-strings to check if you are using string literals correctly.

提交回复
热议问题