Multiple choice technology programming languages

What will the contents of @b array ? my @a = (10, 5, 1); my @b = sort @a;

  1. (1, 5, 10)

  2. (1, 10, 5)

  3. (10, 5, 1)

  4. (5, 10, 1)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Perl's sort function defaults to lexicographic (string) comparison, not numeric. The strings '10', '5', '1' sort as '1' < '10' < '5' because '1' < '5' alphabetically. So @b becomes (1, 10, 5). Option A is incorrect because it assumes numeric sorting.

AI explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) (1, 5, 10) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.

Option B) (1, 10, 5) - This option is the correct answer. When we sort the elements in the array @a, the result is (1, 10, 5) because the elements are sorted in ascending order.

Option C) (10, 5, 1) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.

Option D) (5, 10, 1) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.

The correct answer is B. This option is correct because when we sort the elements in the array @a, the result is (1, 10, 5).