나는 항상 const 포인터를 혼동합니다. 는 사람이 권하는하려고 다음 의 코드 그들이 무슨 말을하는지 알고 있지만 내가 단순 way.Thanksconst 한정자와 Const 포인터
사실char *p="Hello"; /*pointer is variable,so string is*/
*p='M';
p="BYE"; /*works*/
p="Bye"; /*works*/
const char *q="Hello"; /*string is constant pointer is not */
*q='M'; /*Error*/
q="BYE"; /*works*/
char const *s="Hello"; /*string is constant pointer is not */
*s='M'; /*Error*/
s="BYE"; /*works*/
char* const t="Hello"; /*pointer is constant string is not */
*t='M'; /*works*/
t="BYE"; /*error*/
const char* const u="Hello"; /*string is constant,so is pointer*/
*u='M'; /*error*/
u="BYE"; /*error*/
[이 답변에 포함 된] 차트 (http://stackoverflow.com/a/14566215/1322972)는 자신을 만족스럽게 생각하지 않으려 고합니다. 구조에 대한 괜찮은 비난과 단방향 및 이중 간접 포인터 다양한 위치에서. 그리고 타입 선언에 대해 자주 (또는 가끔) 질문이 있으면 북 마킹 할 가치가있는 [** cdecl.org **] (http://cdecl.org)가 항상 있습니다. – WhozCraig
문자열 리터럴은 주소가 할당 된 포인터의 종류에 따라 다르게 해석된다고 생각하는 것 같습니다. 그렇지 않다. 문자열 리터럴 * 항상 *는'char *'유형 값이되지만 * 여전히 문자를 변경할 수는 없습니다 *. – unwind