To find the number of elements it should be q - p +1.
200 ( p) 202 204 (q) 206 208
q-p =(206-202)/2=2
no of elements=2+1=3
That's correct. However, the question is a bit ambiguous. It should be "...to find the number of elements between p and q (inclusive)".
let A[5] is an array of integers {4 byte each element} with base address = 1000
Now suppose , p =1004, and q = 1012
q-p = 8 , now divide it by size of element i.e 8/4 =2 {it is difference between p and q in terms of elements}
saipriyab
if p is holding address of first element and q is holding address of last element the address of last element then:- q-p will give no. of block difference b/w p and q and that would be (n-1)....therefor for finding the size we would use ...q-p+1
@Akash Mittal
i think difference of pointer need not to be devided by size of data...bcoz diffrence of pointer return no. of block b/w them...??
64.3k questions
77.9k answers
244k comments
80.0k users