Why do we need strdup()?

前端 未结 5 1918
花落未央
花落未央 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:02

    String literals may be stored in portions of memory that do not have write privileges. Attempting to write to them will cause undefined behaviour. const means that the compiler ensures that the pointer is not written to, guaranteeing that you do not invoke undefined behaviour in this way.

提交回复
热议问题