KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am a little confused as to how passing pointers works. Let's say I have the following function and pointer, and... EDIT : ...I want to use a pointer to some object as an argument in the function. i.e.: void Fun(int Pointer){ int Fun_Ptr = ---Passed Pointer---; //So that Fun_Ptr points to whatever ---Passed Pointer points to Between the *Pointer and &Pointer notations, I am very confused. I know that *Pointer means give whatever it points to. Do I put void (int *pointer) in the declaration. What about when I use the function? Your assistance is appreciated. EDIT 2: Okay, I now understand that using *variable in a declaration means that a pointer will be passed. However, what about when i use the function? i.e. int main(){ int foo; int *bar; bar = foo; Fun(bar); } EDIT 3: Okay, so correct me if I am wrong: According to the conventions of the above code: bar = &foo means: Make bar point to foo in memory *bar = foo means Change the value that bar points to to equal whatever foo equals If I have a second pointer (int *oof), then: bar = oof means: bar points to the oof pointer bar = *oof means: bar points to the value that oof points to, but not to the oof pointer itself *bar = *oof means: change the value that bar points to to the value that oof points to &bar = &oof means: change the memory address that bar points to be the same as the memory address that oof points to Do I have this right? EDIT 4: Thanks so much for all your help (I wish I could accept more than 1 answer, but I have to go with the first one. I am not sure how a community wiki works exactly, but I will leave it this way for editing (feel free to turn it into a ref guide if you like).
Tags (comma-separated)
Save Edits
Cancel