I take an input for an array, then run a completely unrelated function. Somehow, the values of the array are different after this point. As far as I can tell, the first few values become zero (0).
Here is the opening segment of the main function:
int main()
{
int i, j, k, n;
Nod* root=NULL; //Nod class user defined elsewhere
cin>>n;
int A[n];
for(i=0; i<n; i++)
{
cin>>A[i];
cout<<A[i]<<"\t";//TESTER
}
cout<<endl<<endl;
Nod no[n];
for(i=0; i<n; i++)
no[i].nowhere(n);
for(i=0; i<n; i++)
cout<<A[i]<<"\t";//TESTER
cout<<endl<<endl;
...//rest of main()
...
}
Here is the class Nod with the nowhere() function:
class Nod
{
public: Nod* parent;
Nod* child[];
void nowhere(int n)
{
parent=NULL;
for(int i=0; i<n; i++)
child[i]=NULL;
}
};
Here is a sample input and output:
Input:
5
4 -1 4 1 1
Output:
4 -1 4 1 1
0 0 4 1 1
As far as I can see, the nowhere()
function should not affect the array A[
] at all. Then, how are the values changing?