2008年3月15日 星期六

const and pointer

(1) const char *test= "hello";
the data pointed by test can not be changed
Hence, *test= "hi" is illegal
However, test="hi" is ok

(2) char *const test= "hello"
test is a constant pointer
Hence, *test="hi" is ok
However, test="hi" is illegal

(3) const char *const test= "test"
combine (1) and (2)
Hence, *test= "hi" is illegal, test="hi" is also illegal

沒有留言: