array index 10^3 vs 1000

Hi Everyone,

While I am trying to solve problem:Add two no’s, I initialized the array to arr[10^3] (somewhere I have seen this way in an answer in codechef) and I was wondering that its not working. I tried to calculate the sizeof the array and it shows 9 sizeof(arr)/sizeof(arr[0])) (64 bit OS and arr is initialized as unsigned int type).

What I tried:

  1. Same code I compiled online and the results were same.

  2. Initialized global as well as local but effects none.

Any idea what’s happening? What I am missing. Is this is the correct way or not??

P.S. Here the solution that failed: Solution

@shaswatd that’s because ^ represents XOR and 10^3 is 9.

1 Like

^ is the operator for bitwise XOR for power. You should pow function in which is in math.h in c++ .