Pointer arithmetics in C++ uses sizeof(type) incremention instead of byte incremention?

前端 未结 3 685
南笙
南笙 2021-01-24 07:20

I am confused by the behavior of pointer arithmetics in C++. I have an array and I want to go N elements forward from the current one. Since in C++ pointer is memory address in

3条回答
  •  日久生厌
    2021-01-24 07:56

    pointers point to addresses, so incrementing the pointer p by N will point to the Nth block of memory from p.

    Now, if you were using addresses instead of pointers to addresses, then it would be appropriate to add N*sizeof(type).

提交回复
热议问题