Sunday, 15 June 2014

Pass array by reference and modify values C++ -


I want to write a function which is inArray [3] = {1,2,3,4} and one outside [3] , and modifies outside values ​​[3] within function now the value = {3,4,1,2}.

  int main {int inArray [4] = {1,2,3,4}; Int'l Outre [4]; Myfunction (and innre, and outre); } MyFunction zero (& amp; inArray, & outer) {outArray [0] = inArray [2]; Outre [1] = These arrays [3]; Outre [2] = Inner [0]; Outre [3] = These arrays [1]; }  

I am doing something wrong here, and I am not able to understand exactly how to pass an array by reference and manipulate the values ​​within the function.

See the task and its calls in the following way

  const Size_t N = 4; Zero my function (int (and innre) [n], int (and outrear) [n]) {outer [0] = inarray [2]; Outre [1] = These arrays [3]; Outre [2] = Inner [0]; Outre [3] = These arrays [1]; } Int main () {int inArray [N] = {1,2,3,4}; Int'l Outre [N]; My Function (Aire, Outre); }  

Take an acccount that your definition of an array

  int inArray [3] = {1,2,3,4}; There is no typo in  

and will not be compiled. At least

  should be like inArray [4] = {1,2,3,4};  

or

  int inArray [] = {1,2,3,4};  

No comments:

Post a Comment