memory management - C Function argument value changing by itself -
i have simple function that, after has returned, values of array a[] (passed argument) changed. problem not written on in function, read - supposedly, @ least -. hope can me that:
double *bhaskara(double a[]){ double = a[2], b = a[1], c = a[0]; double raizes[2]; double delta = b*b - 4*a*c; if(delta<=0){//ignora delta para pegar soh parte inteira das raizes raizes[0] = -b/(2*a); raizes[1] = raizes[0]; }else{ raizes[0] = (-b+sqrt(delta))/(2*a); raizes[1] = (-b-sqrt(delta))/(2*a); } return raizes; }
you're returning pointer local variable has gone out of scope. it's undefined behaviour. can, , will, happen.
Comments
Post a Comment