initial pointer [expert c]
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]的更多相关文章
- Impala SQL 语言元素(翻译)[转载]
原 Impala SQL 语言元素(翻译) 本文来源于http://my.oschina.net/weiqingbin/blog/189413#OSC_h2_2 摘要 http://www.cloud ...
- Impala SQL 语言元素(翻译)
摘要: http://www.cloudera.com/content/cloudera-content/cloudera-docs/Impala/latest/Installing-and-Usin ...
- 「2014-3-17」C pointer again …
记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
- 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 ...
- C pointer again …
记录一个比较基础的东东…… C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
- C lang:Pointer operation
Xx_Pointer opteration Do not dereference initialized Pointers Ax_Code #include<stdio.h> int ma ...
- SQL SERVER全面优化-------Expert for SQL Server 诊断系列
现在很多用户被数据库的慢的问题所困扰,又苦于花钱请一个专业的DBA成本太高.软件维护人员对数据库的了解又不是那么深入,所以导致问题迟迟不能解决,或只能暂时解决不能得到根治.开发人员解决数据问题基本又是 ...
- SQLite Expert Professional 3查看SQLite数据
通常在android进行SQLite数据库的处理查看很不方便,于是自己下载了一个SQLite Expert Professional 3可视化工具用来进行查询数据,由于时间问题就不多说了,直接讲使用方 ...
- 苹果手机不支持click文字 需要添加 cursor:pointer 才能 识别可以点击
给一个div 绑定一个 click事件, 苹果手机会识别不了,必须添加一个 cursor:pointer 才能 识别可以点击.安卓正常识别.
随机推荐
- XCode中在提示窗体中对已弃用的API接口画上红线
当我们在XCode中写程序时会不断的出现相关API提示窗体,那敲起来是一个爽啊. 有时候会看到一些API已经弃用了被画上红色的横线.说明该接口已经被弃用,仍保留,但不建议使用,对弃用API实现画横线事 ...
- LeetCode——Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- ZOJ 3329 One Person Game 带环的概率DP
每次都和e[0]有关系 通过方程消去环 dp[i] = sigma(dp[i+k]*p)+dp[0]*p+1 dp[i] = a[i]*dp[0]+b[i] dp[i] = sigma(p*(a[i+ ...
- 用gitolite新建项目,clone后首次push,可能会出现: git: No refs in common and none specified; doing no
用gitolite新建项目,clone后首次push,可能会出现: $ git push No refs in common and none specified; doing nothing ...
- html_day2
总结下今天学的HTML知识.单词 跑马灯标记 <marquee></marquee>属性: direction:滚动的方向 取值:left .right. up. down b ...
- NET中级课--设计模式1
1.分类 创建型 结构型 行为型 2.总体思路 使用接口和抽象类 3.创建型 工厂: 单例:整个系统中对象是唯一的或固定数目的对象如对象池 4.结构型
- C#基础学习心得(一)
类的成员 数据成员:字段,常量(const) 函数成员:方法,属性,索引器,构造函数,析构函数,事件 类的声明 实例成员:对象相关性,不同于同一类的其他实例 静态成员:常量,static修饰的字段,方 ...
- PHP学习笔记二十九【接口】
<?php //定义接口 //接口可以定义属性,但必须是常量而且是public //接口的所有方法必须是public interface Iusb{ public function start( ...
- Eclipse error:Access restriction
报错:Access restriction: The method decodeBuffer(String) from the type CharacterDecoder is not accessi ...
- php对数组中指定键值排序
function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k= ...