I have the following code.
int *x = somefuction();//return array of two elements
string s;
cout << x[0] << " and " << x[1];
This code prints unexpected values. But if I comment out "string s;" row it works fine. What is the reason?
Some function is:
int* getRowCol(int l){
int min = floor(sqrt(l));
int max = ceil(sqrt(l));
int area = 100000;
int result[2];
for (int col = min; col <= max; col += 1){
for (int row = min; row <= col; row += 1){
if (col*row < area && row*col>=l){
area = row*col;
result[0] = row;
result[1] = col;
}
}
}
return result;
}