Understanding-and-Using-C-pointers

#### Why You Should Become Proficient with Pointers

指针的几个用处:

* Creating fast and efficient code
* Providing a convenient means for addressing many types of problems
* Supporting dynamic memory allocation
* Making expressions compact and succinct
* Providing the ability to pass data structures by pointer without incurring a large overhead
* Protecting data passed as a parameter to a function

指针可能出现的几个问题:

* 访问数组和其他数据结构越界
* 引用已经不错在的自动变量
* 在对内容被释放后引用堆内存
* 在指针被分配内存前解引用

pointer的语法和语义都由C specification定义,但有些情况没有显示定义,这种情况下,行为被定义为:

* Implementation-defined
* Unspecified
* Undefined

#### Declaring Pointers

#### How to Read a Declaration

**The trick is to read them backward.**

#### Address of Operator

good practice: initialize a pointer as soon as possible

#### The Concept of Null

几个Null:

* The null concept
* The null pointer constant
* The NULL macro
* The ASCII NUL
* A null string
* The null statement

当NULL被赋值给指针时,意味着这个指针不指向任何东西。

null pointer与未初始化pointer不一样:后者可能包含任何值,前者不指向任何内存位置。

#### To NULL or not to NULL

zero的意义随着上下文而改变。

 

转载于:https://www.cnblogs.com/qiuyi116/p/9008852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值