Do these statements about pointers have the same effect?

后端 未结 4 1157
梦毁少年i
梦毁少年i 2020-11-27 05:59

Does this...

char* myString = \"hello\";

... have the same effect as this?

char actualString[] = \"hello\";
char* myString          


        
4条回答
  •  青春惊慌失措
    2020-11-27 06:16

    No. The first one gives you a pointer to const data, and if you change any character via that pointer, it's undefined behavior. The second one copies the characters into an array, which isn't const, so you can change any characters (either directly in array, or via pointer) at will with no ill effects.

提交回复
热议问题