c++ - How to update an array outside a function (pointing to pointers) -


i have function takes input, pointer 2d array, , pointer 1d array.

int resize(double *x, double **y, int n){ 

the aim of function resize both x , y twice length (n).

i create 2 new arrays- have been doubled in length

double **ytemp = null; double *xtemp = null; xtemp = new double[2*n + 1]; ytemp = new double*[2*n + 1]; 

i loop through , replace values of xtemp , ytemp x , y

after setting them equal 1 other:

        y = ytemp;         x = xtemp;         return 2*n; 

and exiting function, y , x seem lose length.

any on great!

your assignments y , x before return setting local values of variables, not ones passed in caller. that, can change function declaration to

int resize(double *&x, double **&y, int n){ 

which allow changing caller's values.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -