I came across a post How to find a duplicate element in an array of shuffled consecutive integers? but later realized that this fails for many input.
For ex:
a
Here is the code shown in the original question, which is different than your implementation. You have modified it to use a local variable instead of the last member of the array, that makes a difference:
for (int i = 1; i < 1001; i++)
{
array[i] = array[i] ^ array[i-1] ^ i;
}
printf("Answer : %d\n", array[1000]);