Pointer addition and element size

后端 未结 3 1269
无人共我
无人共我 2020-12-16 17:07

At: http://www.fredosaurus.com/notes-cpp/arrayptr/26arraysaspointers.html

Under: Pointer addition and element size

There is the following co

3条回答
  •  [愿得一人]
    2020-12-16 17:55

    because p is pointer to a type with size 4 bytes. + operator on pointers is actually pointer shift. compiler knows the size of pointed type and shifts it by appropriate value

    if you change int to short, p will be shifted by 2 bytes

提交回复
热议问题