when we subtract two pointers will they give the no of cells between the two address stored by pointers or the no of elements (variable)
Regarding subtraction of pointers
Hello @Namanjain123,
The following program answers your question:
Observation:
1.Subtraction gives the (elements+1) between the two addresses
(or is simply the result of a normal subtraction that you perform you in mathematics).
- Why the Output is coming out to be 1?
address of p1: 0x7ffe24a7ea00
address of p2: 0x7ffe24a7ea04
As you know that a single integer variable takes 4 bits space in the memory.
So,
Subtraction=0x7ffe24a7ea04 - 0x7ffe24a7ea00=4 (bits)= 1 (for int one element =4 bits)
Hope, this would help.
Give a like, if you are satisfied.