Computer Science EngineeringVery hard

What does this fragment print? int a[]={3,1,4,1,5}; int s=0; for(int i=0;i<5;i++) s ^= a[i]; printf("%d", s);

  1. A. 14
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: C. 2

Running XOR: 3^1=2, then 2^4=6, then 6^1=7, then 7^5=2.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic