Consider the following code:
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int num,i,ct=0;
vector<int> summ;
i=0;
while(n)
{
if(n%10)
{
cout<<(n%10)*pow(10,i)<<" ";
summ.push_back((n%10)*pow(10,i)); ct++;
}
i++;
n=n/10;
}
cout<<'\n'<<ct<<'\n';
for(i=0;i<summ.size();i++)
{
cout<<summ[i]<<" ";
}
cout<<'\n';
}
If I give the following input:
1
555
The output produced is 5 50 500 3 5 50 499.
I don't understand why the numbers change on push_back().
Can someone please explain why this is happening?