# Thread: comparing the address of a pointer to an array address for size

1. ## comparing the address of a pointer to an array address for size

Good afternoon....
Is it possible to compare the address of a pointer to the address of an array as it is incremented for use as a pointer....so instead of counting with a variable and reaching termination count I was wondering if I could do

Code:
`while (*(&pTx) == &(mssg[5]));`
So if pTx is getting incremented in code within an ISR as such, pTx++, I wanted to wake up at the tail of the ISR and go back to main and act on the above while loop to see if it had reached the address of array mssg[5] ...Note that pTx = mssg; early on in code.

Thanks

2. Sure, but it's just:
Code:
```while (pTx == mssg + 5)
;```

3. Great I will try it.....So that compares the lvalues of the two?

4. I don't think the term "lvalue" is correct here.
Addresses are basically just unsigned integers.
Suppose pTx contains 1020 (i.e., it "points" to address 1020), mssg contains 1000, and the size of the objects to which the pointers point is 4. Then the comparison is just 1020 == 1000 + 5 * 4, which is true.
I wouldn't call 1020, or the result of the addition an "lvalue", although I'm not entirely sure.

EDIT: Actually, now that I read the following, maybe it is an lvalue. The details of "value categories" confuse me.
Value categories - cppreference.com

5. pTx is an lvalue, and from context it is a modifiable lvalue. (mssg + 5) is an rvalue: it is only the "value of an expression", not an object "locator value", i.e., while it is an address, it doesn't necessarily have an address. The cppreference article lists it as a prvalue, but that's a C++ term that is a subset of the set of rvalues.

Popular pages Recent additions