const char *과 char * const 차이
간단하게
const char*는 const char 를 가르키는 포인터 이고
포인터가 가리키는 변수를 다른걸로 바꿀 수 있지만
포인터가 가리키는 변수의 내용은 바꿀 수 없다.
char * const는 char를 가리키는 const 포인터 이고
포인터가 가리키는 변수를 다른걸로 바꿀 수 없지만
포인터가 가리키는 변수의 내용을 바꿀순 있다.
근데.. const 포인터를 어따 써먹지?
링크드 리스트 이런거 구현하거나 범용적으로 쓰이려면 쓸데도 없고
C++의 레퍼런스 처럼 특정 변수를 지정해서 쓰는 용도라면..
커널내에서 정도 밖에 떠오르지 않네?
char * const a; means that the pointer is constant and immutable but the pointed data is not. You could use const_cast(in C++) or c-style cast to cast away the constness in this case as data itself is not constant. const char * a; means that the pointed data cannot be written to using the pointer a. Using a const_cast(C++) or c-style cast to cast away the constness in this case causes Undefined Behavior. |
[링크 : https://stackoverflow.com/questions/10091825/constant-pointer-vs-pointer-on-a-constant-value4]