What will be the output of the following code? [code] #include <bits/stdc++.h> using namespace std; void func(int arr[], int left, int

Trần Vũ

New member
What will be the output of the following code?
Code:
#include <bits/stdc++.h> 
using namespace std; 
void func(int arr[], int left, int right) 
{     
	while (left < right) 
	{ 
		int temp = arr[left]; 
		arr[left] = arr[right]; 
		arr[right] = temp; 
		left++; 
		right--; 
	} 
}	 
void printArray(int arr[], int size) 
{ 
    for (int i = 0; i < size; i++) 
    cout << arr[i] << " "; 
} 
int main() 
{ 
	int arr[] = {1,4,3,5}; 
	int n = sizeof(arr) / sizeof(arr[0]); 
	func(arr, 0, n-1); 
	printArray(arr, n); 
	return 0; 
}
A. 5 1 4 3
B. 3 5 1 4
C. 5 3 4 1
D. error
 

Tìm kiếm

Back
Top