p和c分别被赋予了c[0]的地址和c[5]的地址,也就是10和60的地址,两个地址是怎么减出5的?

img

地址相减,假如P的地址为1,那么S的地址是6,所以相减是5。就是地址差

int指针相减,等于地址相减/sizeof(int)等于20/4=5。
指针相减是指针地址相减,不是指针所指内容相减。

FROM https://en.cppreference.com/w/c/language/operator_arithmetic#Pointer_arithmetic

Pointer arithmetic

If the pointer P1 points at an element of an array with index I (or one past the end) and P2 points at an element of the same array with index J (or one past the end), then
P1-P2 has the value equal to I-J and the type ptrdiff_t (which is a signed integer type, typically half as large as the size of the largest object that can be declared)