Create TOC

2003년 5월 15일

Pointers and Constants

StroustrupThe C++ Programming Lanugage Chapter 5 중 일부분

void f1(char *p)
{
	char s[] = "Gorm";

	const char *pc = s;         // pointer to constant
	pc[3] = 'g';                // error:pc points to constant
	pc = p;                     // ok

	char *const cp = s;         // const pointer
	cp[3] = 'a';                // ok
	cp = p;                     // error: cp is constant

	const char *const cpc = s;  // const pointer to const
	cpc[3] = 'a';               // error: cpc points to constant
	cpc = p;                    // error: cpc is constant
}