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
Post a Comment