a.c:38: 錯(cuò)誤:將‘char’賦值給‘char [1]’時(shí)類型不兼容
數(shù)組與指針的差別.
delete [] p
delete p
如何看出差別呢?
delete 如何知道我刪除的是一個(gè)數(shù)字?
等價(jià)數(shù)組確實(shí)指針等價(jià).
char a[26];
a+3 ='a' ;
a[3] ='a' ;
打印
%c a 不能正常輸出,因?yàn)閍的內(nèi)容是數(shù)組首地址.
%d a 輸出數(shù)組a的內(nèi)存地址.
%s a 輸出a的內(nèi)容,字符串正常.
void foo(char c); // a function which takes a char as a parameter
void bar(char c[1]); // a function which takes a char* as a parameter
void baz(char c[12]); // also a function which takes a char* as a parameter
In bar and baz, c
never has array type - it looks like an array type, but it isn't, it's just a fancy special-case syntax with the same meaning as char *c
. Which is why I put the quotation marks on "use" - you aren't really using char[1]
at all, it just looks like it.參考:
http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c
http://stackoverflow.com/questions/4120658/difference-between-char-and-char1
數(shù)組初始化:
http://stackoverflow.com/questions/2204176/how-to-initialise-memory-with-new-operator-in-c