What is the output of the following code segment?

29 views
  • 10 20 30 40 50
  • 10 20 50 40 30
  • 10 20 50 30 40 (Correct Answer)
  • 10 50 20 40 30

Explanation

Answer: c) 10 20 50 30 40

Explanation: The given code segment swaps the elements at positions i and j in the array arr[] until i >= j. In this case, i = 2 and j = 4, so the elements at positions 2 and 4 are swapped first (30 and 50), then the elements at positions 3 and 3 are swapped (40 and 40). The resulting array is {10, 20, 50, 30, 40}, which is printed in the for loop.

Comments (0)

No comments yet. Be the first to comment!

Want to practice more?

Explore thousands of MCQs across every exam category on Exams Nepal.

Find More MCQs