Why I am getting 0 while passing inputs

#include
using namespace std;
int main() {
int n,ans=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
//int no;
cin>>a[i];
int ans = ans^a[i];
}
cout<<ans;
return 0;
}

@Nasir share your code using cb ide and whats the question?

Unique number from bitmasking

@Nasir you are declaring ans everytime inside the for loop
do
ans=ans^a[i] not it ans=ans^a[i]
is it clear now?

thank you bhai, its my fault

@Nasir np just mark it resolved and hit like if you want :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.