Vidyalelo
Data Structure · Q421

Miscellaneous on Data Structures

Programming · Data Structure · question 421

Q421

What will be the output for following code? #include #include #include using namespace std; void swap(char *x, char *y) char temp; temp = *x; *x = *y; *y = temp; void func(char *a, int l, int r) int i; if (l == r) cout<<a<<” ,”; else for (i = l; i <= r; i++) swap((a+l), (a+i)); func(a, l+1, r); swap((a+l), (a+i)); int main() char str[] = "AB"; int n = strlen(str); func(str, 0, n-1); return 0;

A.
AB,BA,
Answer
B.
BA,AB,
C.
AB,BA
D.
BA,AB,

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board