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 小高 閱讀(252) 評論(0)  編輯  收藏 所屬分類: C

          導航

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

          統計

          常用鏈接

          留言簿(3)

          隨筆分類(352)

          收藏夾(19)

          關注的blog

          手冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 甘德县| 潼关县| 三都| 盐山县| 普格县| 黄山市| 大埔区| 濮阳县| 五指山市| 静乐县| 霞浦县| 高邮市| 嘉荫县| 北宁市| 乌拉特前旗| 山丹县| 桓仁| 天峻县| 石门县| 寻乌县| 普洱| 临高县| 闽清县| 萨嘎县| 伊川县| 唐海县| 凤庆县| 大丰市| 堆龙德庆县| 茌平县| 石嘴山市| 蒲江县| 西乌珠穆沁旗| 博乐市| 潍坊市| 郸城县| 镇安县| 特克斯县| 金溪县| 诸暨市| 襄城县|