|
-
November 8th, 2009, 12:53 PM
#6
Re: Segmentation fault
You shouldn't talk about an array being passed to the function. The array is *not* what's being passed. Instead, your are passing a pointer to the array.
The pointer itself is passed by value, so modifications to the pointer inside the function are not reflected afterwords. But the address held by the pointer is the same whether you're working from a copy of the pointer or not; so you're free to modify that memory at will, and it will be reflected outside the function.
Think of it like a dog on a leash. You can put as many leashes as you like on the same dog, and changes made to one leash won't affect any of the others. But they're all attached to the same dog. If you attach one of the leashes to a second dog, that doesn't affect anything relating to any of the leashes attached to the first. In this analogy, leashes are pointers and dogs are the arrays they're directed at.
Last edited by Lindley; November 8th, 2009 at 12:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|