반응형
  • char[]의 경우는 local data를 가지는 포인터이다. 따라서 수정가능.
  • char* 경우는 global static data 할당한 후 그의 포인터를 가지는 것이기 때문에 수정 불가능.!
char str[] = "hello world";  //local data 수정 O
str[3] = '3'; 
cout << str << endl; 

char *str2 = "hello world"; //global static data 수정 X
str2[3] = '3'; //error 

 

반응형

'C++' 카테고리의 다른 글

[C++] 스택과 힙  (0) 2020.07.23
[C++] 메모리누수 체크  (0) 2020.07.23
[C++] 포인터(Pointer)와 레퍼런스(Reference : 참조자)의 차이  (0) 2020.07.22
[C++] char*, const char*, char* const  (0) 2020.07.21
C++ assign (vector, map)  (0) 2020.07.16

+ Recent posts