Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

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

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 (reverse 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
Last Updated : 21 Dec, 2022
Like Article
Save Article
Similar Reads