String | Data Structure Quiz for Beginners | Question 7

Last Updated :
Discuss
Comments

What is missing in the given code?

C++
#include <bits/stdc++.h>
using namespace std;

void reverseStr(string& str)
{

    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}

// Driver program
int main()
{
    string str = "geeksforgeeks";
    reverseStr(str);
    cout << str;
    return 0;
}

swap function is not defined

string is not defined here.

Variable n is not declared anywhere.

None

Share your thoughts in the comments