6.8a Pointer arithmetic and array indexing

原完整教程链接:6.8a Pointer arithmetic and array indexing

1.
/*
   The C++ language allows you to perform integer addition or 
   subtraction operations on pointers. 

   Note that ptr + 1 does not return the memory address after ptr, but 
   the memory address of the next object of the type that ptr points 
   to. If ptr points to an integer (assuming 4 bytes), ptr + 3 means 3 
   integers (12 bytes) after ptr. If ptr points to a char, which is always 
   1 byte, ptr + 3 means 3 chars (3 bytes) after ptr.

   When calculating the result of a pointer arithmetic expression, the 
   compiler always multiplies the integer operand by the size of the 
   object being pointed to. This is called **scaling**.
*/

2.
// Generalizing, array[n] is the same as *(array + n), where n is an 
// integer. The subscript operator [] is there both to look nice and for 
// ease of use.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,768评论 0 33
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 11,132评论 6 13
  • 考研最后两个月是巩固知识的黄金时期,尤其是背诵记忆各科的重点内容。很多考研人抱怨自己背的知识很快就会忘记,或者根本...
    刘灰灰阅读 2,110评论 13 6
  • 文:骏少 世人皆赞 金陵景 我却叹 华夏悲苦在金陵 哀叹都督周公瑾 大江东去 羽扇纶巾 无奈少主降晋献金陵 哀叹南...
    骏少的宅院阅读 533评论 4 9