UGC-NET | UGC NET CS 2018 Dec – II | Question 41

Consider the C/C++ function f() given below:

void f(char w [ ] )
{
 int x = strlen(w); //length of a string
 char c;
 For (int i = 0; i < x; i++)
  {
    c = w[i];
    w[i] = w[x - i - 1];
    w[x - i - 1] = c;
  }
} 

Which of the following is the purpose of f() ?
(A) It output the content of the array with the characters rearranged so they are no longer recognized a the words in the original phrase.
(B) It output the contents of the array with the characters shifted over by one position.
(C) It outputs the contents of the array in the original order.
(D) It outputs the contents of the array in the reverse order.


Answer: (C)

Explanation: Given code,

c = w[i];
w[i] = w[x - i - 1];
w[x - i - 1] = c;

It swaps the elements which are at ith and (x-i-1)th, so reverse the input order.

From the mid point to end, again same code applied and reverse (revere of input order).
Therefore, original order of input preserve at the end.

Option (C) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.