How to only the value of an array is passed? In order to modify the function elements, not to change the original array,
# include & lt; Stdio. H>
Void change1 (int * array, int n);
Void change2 (int array [], int n);
Int main () {
An int array []={1, 2, 3, 4, 5};
Change1 (array, 5);
for (int i=0; I & lt; 5; + + I) {
Printf (" % d ", array [I]);
}
}
Void change1 (int * array, int n) {
for (int i=0; I & lt; n; + + I) {
* (array + I)=0;
}
}
Void change2 (int array [], int n) {
for (int i=0; I & lt; n; + + I) {
Array [I]=0;
}
}
CodePudding user response:
Add a const array parameters should be able to achieve your requirement,CodePudding user response:
Can put the whole array in structure, the parameters of the structure type,CodePudding user response:
Limited is the structure of the array size must be constant,CodePudding user response: