Addition of two pointers in c or c++ not supported. why?

后端 未结 3 1920
南旧
南旧 2020-12-03 14:09

Why addition of two pointers not supported in c or c++.

When I do,

int *ptr,*ptr1;
int sum = ptr + ptr1;

C or C++ throws an error.

3条回答
  •  忘掉有多难
    2020-12-03 14:26

    To put it plainly, difference between two pointers give the number of elements of the type that can be stored between the two pointers, but adding them doesn't quite give any meaningful functionality. If there's no meaningful functionality then doesn't it make sense that it is not supported.

提交回复
热议问题