c - Changing a variable in different function using pointer -


I've got some code and I do not have permission to change the structure. I found an array named arr in my main function:

  int arr [4] = {1,2,3,4}  

my To change the values ​​of this array in another function, close to Which is used inside the main function:

  change_array (arr);  

change_array method to any other C file has been implemented in. I am only allowed to make changes within the change_array function.

  zero change_array (zero * the_array) {}  

In this function I want to change values ​​from arr I know that I use this Get the first value of the array:

  int first_value = * (int *) the_array;  

And I can get a place using the following value:

  int location = the_array;  

I tried to change the value with:

  * the_array = 1;  

But did not he solve my problem any thoughts?

* the_array indicates first element (value 1 in your case). You have to use [] or move around the array.

  • You also need the size of the array so that you can restart the array without limits. Here is an example:

      zero change_array (zero * the_array, int size) {int a = 0, b = 0,   I = 0; // How to set and iterate (i = 0; i  

  • Comments