I've got some code I'm mantaining with the following variable declaration:
char tmpry[40];
It's being used with this function:
char *SomeFunction(char *tmpryP) {
// Do stuff.
}
The function call is:
SomeFunction(&tmpry[0]);
I'm pretty damn sure that's just the same as:
SomeFunction(tmpry);
I've even checked that the char* pointer in SomeFunction ends up pointing to the same memory location as the array in both cases.
My question is a sanity check as to whether the two function calls are identical (and therefore the original programmer was just being nasty)?
they are exactly the same.
someArray[i]
means exactly
*(someArray + i)
where someArray in the second case is a pointer to the memory location. Similarly,
&someArray[i]
means exactly
(someArray + i)
In both these cases the terms are pointers to memory locations.
The two are equivalent and I think SomeFunction(tmpry); is more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With