Protecting Array Contents
When you write a function that processes a fundamental type, such as int, you have a choice of passing the int by value or of passing a pointer-to-int. The usual rule is to pass quantities by value unless the program needs to alter the value, in which case you pass a pointer. Arrays don't give you that choice; you must pass a pointer. The reason is efficiency. If a function passed an array by value, it would have allocated enough space to hold a copy of the original array, and then copied all the data from the original array to the new array. It is much quicker to pass the address of the array and have the function work with the original data.
This technique can cause problems. The reason C ordinarily passes data by ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access