Originally Posted by
nadroj
2) pass-by-reference
- lets say we have some math program that has a 100 by 100 matrix of integers. we also have a function to search a given matrix for the value at a specific row-column pair. if the function used "pass-by-value" for the matrix parameter, it would involve (the computer automatically) making a copy of the 100*100*(size of integer, usually 4 bytes)=40000 byte matrix so it can be used in the function, then forgotten about after the search function has returned.
- thankfully, "by default", arrays and pointers are "passed-by-reference", where only a copy of the fixed-size pointer argument is passed, rather than the actual data structure.
- all primitive data types are passed by value, unless "told" otherwise. these are things such as char, int, float, etc.