Pass array by reference and modify values C++ -


i want write function takes inarray[3] = {1,2,3,4} , outarray[3], , modifies outarray[3] within function contain values = {3,4,1,2}.

int main{  int inarray[4] = {1,2,3,4};  int outarray[4];   myfunction(&inarray, &outarray); }  void myfunction(&inarray, &outarray){   outarray[0] = inarray[2];   outarray[1] = inarray[3];   outarray[2] = inarray[0];   outarray[3] = inarray[1]; } 

i'm doing wrong here, , don't precisely understand how pass array reference , manipulate values inside function.

the fiunction , call can following way

const size_t n = 4;  void myfunction( int ( &inarray )[n], int ( &outarray )[n] ) {   outarray[0] = inarray[2];   outarray[1] = inarray[3];   outarray[2] = inarray[0];   outarray[3] = inarray[1]; }  int main() {  int inarray[n] = {1,2,3,4};  int outarray[n];   myfunction( inarray, outarray ); } 

take acccount definition of array

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

contains typo , not compiled. there must @ least like

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

or

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

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -