![]() |
Why are these the same?
void UseArray (int a [])
void UseArray (int *a) apparently these are the same. I have a guess why, so I'll say that, and hopefully someone will be kind enough to tell me if I'm wrong (and what the real reason is, if so). void UseArray (int a []): Passed the address of the array to the function UseArray. void UseArray (int *a): Passes the thing the pointer points to (the value of a) to the function, and by doing so, also passes the address of a. |
|
If A[N] and *(A+N) mean the same thing...
&A[N] == &*(A+N) &A[N] == (A+N) Set N to 0 &A[0] == (A+0) &A[0] == (A+0) == A |
I have never seen anyone solve a pointer like that before, lol.
|
It's just as well you haven't.
Quote:
|
The short explanation is that, by convention, the C compiler treats the name of an array like it is a pointer and, conversely, a pointer like it contains the address of the first element of an array, in some circumstances.
|
A longer explanation can be found by referring to the C++ standard:
Quote:
|
so for:
:
int x[10];for a lot of operations would it be more efficient to use: :
x[0]instead of: :
x?????????????????????? i am rather curious about this now. |
Not quite, bl00d. For some use cases, "x[0]" and "*x" have the same meaning. Or, alternatively, "x" and "&x[0]" have the same meaning.
Keep in mind that an array and a pointer are different things. We're talking about cases where the compiler converts one into the other so they appear to be the same. |
thanks for the replies everyone :)
|
| All times are GMT -5. The time now is 2:15 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC