How exactly pointer subtraction works in case of integer array?

前端 未结 4 549
自闭症患者
自闭症患者 2020-12-17 05:51
#include
int main()
{
    int arr[] = {10, 20, 30, 40, 50, 60};
    int *ptr1 = arr;
    int *ptr2 = arr + 5;
    printf(\"Number of elements between          


        
4条回答
  •  粉色の甜心
    2020-12-17 06:18

    Each array element is an int and there are 5 elements between both the pointers. Thus there will be 5*sizeof(int) amount of bytes in between both the pointers.

提交回复
热议问题