Why must a pointer to a char array need strcpy to assign characters to its array and double quotes assignment will not work?

前端 未结 9 1752
耶瑟儿~
耶瑟儿~ 2021-02-14 09:23

The first example does not work when you go to delete the pointer. The program either hangs when I add the null terminator or without it I get:

Debug Assertion Fai

9条回答
  •  天涯浪人
    2021-02-14 09:58

    In the first example you are chaning the value at, in the second you are changing the value of what at points to. Assigning a char * to a double quoted string assigns it to a static const pointer.

    In particular, in the first example at now points a different location in memory.

提交回复
热议问题