initial differece between pointer and array

Both arrays and pointers can be initialized with a literal string in their definition. Although these cases look the same, different things are happening. A pointer definition does not allocate space for what's pointed at, only for the pointer, except when assigned a literal string. For example, the definition below also creates the string literal:

char *p = "breadfruit";
Note that this only works for a string literal. You can't expect to allocate space for, for example, a float literal:
                                   float *pip = 3.141;     /* Bzzt! won't compile */

A string literal created by a pointer initialization is defined as read-only in ANSI C; the program will  exhibit undefined behavior if it tries to change the literal by writing through p. Some implementations put string literals in the text segment, where they will be protected with read-only permission.

eg:          char *s = "hello world";

*s = 'w';

would generate an error when running the program.

An array can also be initialized with a string literal:
                          char a[] = "gooseberry";
     In contrast to a pointer, an array initialized by a literal string is writable. The individual characters can later be changed. The following statement:

strncpy(a, "black", 5);
gives the string in the array the new value "blackberry".

initial pointer [expert c]的更多相关文章

  1. Impala SQL 语言元素(翻译)[转载]

    原 Impala SQL 语言元素(翻译) 本文来源于http://my.oschina.net/weiqingbin/blog/189413#OSC_h2_2 摘要 http://www.cloud ...

  2. Impala SQL 语言元素(翻译)

    摘要: http://www.cloudera.com/content/cloudera-content/cloudera-docs/Impala/latest/Installing-and-Usin ...

  3. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

  4. c pointer and array

    Pointer:  A pointer is a variable that contains the address of a variable. if c is a char and p is a ...

  5. C pointer again …

    记录一个比较基础的东东…… C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

  6. C lang:Pointer operation

    Xx_Pointer opteration Do not dereference initialized Pointers Ax_Code #include<stdio.h> int ma ...

  7. SQL SERVER全面优化-------Expert for SQL Server 诊断系列

    现在很多用户被数据库的慢的问题所困扰,又苦于花钱请一个专业的DBA成本太高.软件维护人员对数据库的了解又不是那么深入,所以导致问题迟迟不能解决,或只能暂时解决不能得到根治.开发人员解决数据问题基本又是 ...

  8. SQLite Expert Professional 3查看SQLite数据

    通常在android进行SQLite数据库的处理查看很不方便,于是自己下载了一个SQLite Expert Professional 3可视化工具用来进行查询数据,由于时间问题就不多说了,直接讲使用方 ...

  9. 苹果手机不支持click文字 需要添加 cursor:pointer 才能 识别可以点击

    给一个div 绑定一个 click事件,  苹果手机会识别不了,必须添加一个 cursor:pointer 才能 识别可以点击.安卓正常识别.

随机推荐

  1. 十分钟搭建自己的hadoop2/CDH4集群

    版本及准备 我部署的是hadoop-2.0.0-cdh4.2.0.tar.gz,下载地址为http://archive.cloudera.com/cdh4/cdh/4/hadoop-2.0.0-cdh ...

  2. [CSS3] CSS Display Property: Block, Inline-Block, and Inline

    Understanding the most common CSS display types of block, inline-block, and inline will allow you to ...

  3. [Git] --no-verify

    Somtimes, the project might set the commit message guide line, if your commit doesn't meet the requi ...

  4. 男同胞爱小秘籍--作为爱他的女朋友了几天C规划

    各位男同胞,不知道你的女朋友没有在过去的一问天,你这个问题~~ 场景重现: 女友:"今天天气不错." 你们:"对" 女友:"今天是我们知道它的最初几天 ...

  5. iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程

    iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程 一.引言 二.初识CoreAnimation 三.锚点对几何属性的影响 四.Layer与View之间的关系 ...

  6. hadoop之mapreduse 在Eclipse下的调试环境篇

    搭建完毕环境后,開始调试mapreduse程序. 可是遇到不停的报错.本人非常讨厌在自己的操作系统环境变量里设置来设置去,包含linux也是. 通常喜欢把设置环境变量在启动程序的脚本中.让脚本自己执行 ...

  7. parseInt引发的血案

    今天做了个专题活动,页面头上有个倒计时 专题做完后上线了,没发现有什么问题,结果,运营MM突然和我说:技术哥哥出问题了,360浏览器在秒数从10到09的时候直接变成 00 了! 一看我去真的,该死的3 ...

  8. Xcode 常用快捷键及代码自动排版

    1. 文件CMD + N: 新文件CMD + SHIFT + N: 新项目CMD + O: 打开CMD + S: 保存CMD+OPt+S:保存所有文件CMD + SHIFT + S: 另存为CMD + ...

  9. hdu 1099 Lottery

    这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客. HDU 1099 Lottery Time Limit: 2000/1000 MS (Java/Others)     ...

  10. (原+转)error C2872: “ACCESS_MASK”: 不明确的符号 C:\Program Files (x86)\Windows Kits\8.1\Include\um\ktmw32.h 125

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5500795.html 参考网址: http://www.lxway.com/88515256.htm ...