Consider the below program. What is the expected output?
void fun( int arr[], int start, int end)
{ while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
} |
(A)
swapping the elements pairwise
(B)
sorting the elements
(C)
Reverse an array
(D)
None
Answer: (C)
Explanation:
The above code is for reversing an array of elements., we are just swapping the first and last element of the array, and the whole array is reversed.
For more reference:
https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/
Hence Option(C) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post