我是靠谱客的博主 懵懂鼠标,这篇文章主要介绍C++ self-learning notes(2),现在分享给大家,希望可以做个参考。

1. const

The keyword const guarantees that the specified data won't be changed if the data is processed in the codes. 

EXAMPLE:

085048_xitp_2968040.png

RESULT:

085220_ja6i_2968040.png

As you can see in the example, n is set constant. However, in the function, the input parameter (n) would be changed if the input parameter is not constant. In the result, you can see that even though n is changed to 7 during the process, n is still (or may be reset to) its initial value 5 after the processing.

When you define a pointer:

1) const int * a : this command means the value pointed by the pointor a is a constant value.

2) int * const a : this command means that the pointer itself is a constant value.

3) const int * const a : this command means both the pointer and the value pointed to are constatnt.

 

2. new & delete

New and delete are operations on computer's memory (dynamic memory).

commands:

1) new: pointer = new type;                                       2) delete:  delete pointer;        ......single value

     or    pointer = new type[number of elements];           or      delete[] pointer;      ...... array

 

So far, my understanding is about this much on this subject. It will be updated in the future when I learn more about const, new and delete during work.

( For anyone other than myself see this, I'm a Chinese guy and I'm writing in English because I'm trying to improve my English writing skills. Pardon me for that. If you see and grammatic or spelling mistake, please leave a comment)

Here is a few links to some very good references online:

http://blog.csdn.net/Eric_Jo/article/details/4138548

http://blog.csdn.net/smf0504/article/details/52311207

http://www.cplusplus.com/doc/tutorial/dynamic/

转载于:https://my.oschina.net/u/2968040/blog/994245

最后

以上就是懵懂鼠标最近收集整理的关于C++ self-learning notes(2)的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部