dimanche 12 avril 2020

why the difference between two pointers pointing to different elements of an array is the no of elements between these two pointers?

int main()
{
    int arr[]={2,3,5,6,8};
    int *ptr;

    ptr=&arr[3];
    cout<<ptr-arr;
}

Q.why the answer is 3 after compiling the code i.e. as it should be 3*sizeof(int) which in this case should be 3*4=12?

Aucun commentaire:

Enregistrer un commentaire