enter image description here Shouldn't the answer be 2nd ques?
ptr1 saves the address of arr[0] and ptr2 saves the address of arr[3]. So (ptr2-ptr1) should be ((34(size of float)) -(04)) i.e., subtraction of address not the subtarction of index..
enter image description here Shouldn't the answer be 2nd ques?
ptr1 saves the address of arr[0] and ptr2 saves the address of arr[3]. So (ptr2-ptr1) should be ((34(size of float)) -(04)) i.e., subtraction of address not the subtarction of index..
You wrote that
So according to the usual arithmetic
ptr2 - ptr1is equal to3.:)The same is valid for the pointer arithmetic.
From the C++20 Standard (7.6.6 Additive operators)
That is after this line of code
the value of the pointer
ptr1is equal to&arr[0]and the value of the pointerptr2is equal tp&arr[3]. The difference yields the number of elements of the array between the first and the fourth elements in the array.To get the value of the difference of two addresses you can write for example