Output is 3402 (3 and 402) but it is numerical hence answer should be 3402.
Initially p =0
in the first for loop
Itr 1 : arr[0] = 100 + 0 = 100 p++ => p = 1
p++ => p=2
Itr 2 : arr[2] = 300 + 2 = 302 p++ => p =3
p++ => p=4 (exit)
p-- => p=3.
next for loop q=8; inner p has scope only in its loop
Itr 1 : p = q right shift 1 => 8 (1000) >> 1 => 0100 (4)
arr[4] = 500+1 = 501
q-- = 7
Itr 2 : p = q right shift 1 => 7 (0111) >> 1 => 0011 (3)
arr[3] = 400 + 1 = 401
q-- = 6
Itr 3 : p = q right shift 1 => 6 (0110) >> 1 => 0011 (3)
arr[3] = 401 + 1 = 402
q-- 5 (exit)
Hence answer is p(outer) = 3, arr[p] = arr[3] =402