Interview Question
Country: United States
If you are doing only read only operation in the called function then there is no problem but any change in element of the array passed by value will definitely change the array.
Another way to pass an array by value is wrap it in a structure.
You can only wrap an array in a structure like that if the size of the array is known at compile time, though, so this isn't a very general solution.
Do you just want to ensure that no changes are made, or do you want changes to be made but not reflected in the calling function? If the latter, you must clone because it's clear that 2 copies of the data need to exist simultaneously: one in the called function and one in the calling function. If the former, you can say that the array is const.
- eugene.yarovoi June 25, 2012