Quote:
Original posted bi jmiller
When you pass a pointer, like:
int *pInt;
blah(pInt);
do you pass the value at the address that pInt holds, or do you pass the address?
It passes the address, which pInt holds.
Quote:
Original posted bi jmiller
On my second example,
void Pass(User *UD, int index) {
cout << UD[index].Name;
}
int main() {
User *UserDatabase = new User[10];
Pass(UserDatabase,5);
}
if i want to reference back the memory that UserDatabase points to from Pass, don't I need to use ptr-ptr?
like:
No, unless you are changing the address. Why don't you read the links I gave you?
Quote:
Original posted bi jmiller
void Pass(User **UD, int index)
cout << (*Ud)[index].Name;
}
and then call pass like this: Pass(&UserDatabase)? Wouldn't this actually reference back to the original memory? If so, what does having this:
void Pass(User *UD,int index); Pass(UserDatabase)
do?
This I will have to explain as it is not explained in the links.
void Pass(User **UD, int index);//Function prototype
......
Pass(&UserDatabase);
UD : UD==&UserDatabase : UD contains the address of the pointer, UserDatabase. You would never change this, if you do, UD is no longer pointing to UserDatabase (which makes the whole ptr-to-ptr thing pointless.)
*UD : *UD==UserDatabase : Anything, you give to *UD, goes into UserDatabase pointer;You are effectively changing UserDatabase itself.
**UD : **UD==*UserDatabase : Self-explanatory
-------------------------------------
void Pass(User *UD, int index);//Function prototype
......
Pass(UserDatabase);
UD : UD is another pointer which points to the same thing, UserDatabase is pointing. Changing UD doesn't change UserDatabase itself as it is another variable.
*UD : Self-explanatory
------------------------------------
Quote:
Original posted bi jmiller
thanks for all your patience, i really appreciate you guys
jmiller
It took me quite a while to understand it too. Anyway it is good to know them as some Win32 APIs and DirectX APIs make use of ptr-to-ptr.