You declare an array hand
as having three entries, then you index it using indexes 1
through 3
. But arrays in C have indexes from 0
to size-1
(e.g. 2
in your case).
So you write/read to/from out of bounds of the array, leading to undefined behavior.
Change the indexes of your array to 0
through 2
and it should work fine.