JUST DO IT ~

我只想当个程序员

关于数组


a.c:38: 错误:将‘char’赋值给‘char [1]’时类型不兼容 

数组与指针的差别.
delete [] p 
delete  p 
如何看出差别呢?
delete 如何知道我删除的是一个数字?


等价数组确实指针等价. 
 
char a[26];
a+3 ='a' ; 
a[3] ='a' ; 

打印
%c  a  不能正常输出,因为a的内容是数组首地址.
%d  a  输出数组a的内存地址.
%s  a  输出a的内容,字符串正常.






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

数组初始化: 

http://stackoverflow.com/questions/2204176/how-to-initialise-memory-with-new-operator-in-c 



posted on 2015-08-25 15:38 小高 阅读(234) 评论(0)  编辑  收藏 所属分类: C


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2015年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

统计

常用链接

留言簿(3)

随笔分类(352)

收藏夹(19)

关注的blog

手册

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜