Last Updated : 14 Feb, 2019

What will be the output of the following program?

#include

int main()
{
int arr[] = {12, 12, 14, 90, 14, 14, 14};
int n = sizeof(arr)/sizeof(arr[0]);

int res = 0, i;

for (i = 0; i < n; i++) res ^= arr[i]; printf (\"%d \", res); return 0; } [/sourcecode]

(A) 12
(B) 14
(C) 90
(D) Error


Answer: (C)

Explanation: In given a set of numbers {12, 12, 14, 90, 14, 14, 14}, 12 and 14 occur even number of times except 90. Hence 90 is the odd number of times occurring elements, which is the output.

Quiz of this Question


Share your thoughts in the comments