Multiple choice technology programming languages

Consider the following program code @array= (“Y”,”W”,”X”); @array=sort(@array); unshift(@array , ”Z”); print($array[0]); What is the output of this code

  1. W

  2. X

  3. Y

  4. Z

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

The code first sorts the array (W, X, Y), then uses unshift to add Z at the beginning. After unshift, @array becomes (Z, W, X, Y), so $array[0] is Z. Sorting arranges elements alphabetically, and unshift prepends elements to the array's start, modifying the index positions.

AI explanation

After sort(@array) on ('Y','W','X'), the array becomes alphabetically ordered: ('W','X','Y'). unshift(@array, 'Z') then adds 'Z' to the front of the array, making it ('Z','W','X','Y'), so $array[0] — the first element — is 'Z'.