I had been studying the algorithm for finding lonely integers in an array, and here is the implementation:
int arr[] = {10, 20, 30, 5, 20, 10, 30};
int LonelyInteger = 0;
for(int i=0; i< 7; i++)
{
LonelyInteger = LonelyInteger ^ arr[i];
}
The result is 5
.
My question is - supposedly the integers (getting generated by the XOR
operation) are too large due to this operation:
LonelyInteger ^ arr[i]
Which leads to a potentially large integer which cannot be represented by the datatype say int
in this case. My questions are:
- Is it even possible that
XOR
will generate such a large integer value that cannot be stored in theint
type? - If it is not possible that this can happen then is there a proof for this?