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 才能 识别可以点击.安卓正常识别.
随机推荐
- 从手工测试逆袭为NB自动化测试的学习路线
在开始之前先学习两个工具商业web自动化测试工具请学习QTP:QTP的学习可以跳过,我是跳过了的.开源web自动化测试工具请学习Selenium:我当年是先学watir,再学selenium 这里主要 ...
- [Redux] Extracting Action Creators
We will create an anction creator to manage the dispatch actions, to keep code maintainable and self ...
- ci 笔记
一.CI的HelloWorld! 注意:CI禁止直接通过文件目录来访问控制器. ./application/controllers/hello.php 1 <?php 2 //放止用户直接通过路 ...
- git commit -am 合并操作
二,合并的操作 1, 首先按需修改文件 echo >> lz66303.txt 2, 然后按需提交被修改的文件到HEAD缓存区,并把这个修改记录到分支中 git commit -am&qu ...
- linux用户创建删除以及文件权限查看修改
一. 1.查看用户 命令如下:whoami 2.创建用户 创建用户命令:sudo adduser hello 超级用户是 root 删除用户名命令:sudo deluser hello --remov ...
- 不用position,让div垂直居中
先弄懂after伪类的用法,就可以很容易理解了. <!DOCTYPE html> <html lang="en"><head> <meta ...
- JSP基础学习(一)
1.jsp和servlet是javaEE规范的两个基本成员,是java web开发的重要知识,jsp和servlet本质上是一样的,因此jsp最终必须编译成servlet才能运行,或者说jsp是生成s ...
- Winform开发之窗体传值
Winform的窗体之间的数据传递是开发的必备技术,下面介绍几种典型的传值方法 1.构造函数传值,但这种方法是单向的(推荐) 上代码,先传值 private void button2_Click(ob ...
- BaceModel
https://github.com/nicklockwood/BaseModel 字典封装成model 自动封装 要求属性的名字与字典一样 不能有对象 如果其中有需要自己封装的对象属性 重写setW ...
- Mock测试框架
一.前言 使用Mock框架进行单元测试,能够使用当前系统已经开发的接口方法模拟数据.(未写完,慢慢完善) 二.例子 1.引用Moq