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 ...
Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.