passing string object by pointer & access length() method

  accessibility, c++, class, pass-by-pointer, string
#include <bits/stdc++.h> 
using namespace std;    

     void reverseStr(string* str) 
        { 
            int n = str->length(); 
        }
    int main() 
    { 
        string str = "geeksforgeeks"; 
        reverseStr(&str); 
        cout << str; 
        return 0; 
    }

why am I getting segmentation fault in this code.I want to pass string variable by pointer,as there is a class named by string & length() method within that class.So I think I can access using ‘->’ operator.

Source: Windows Questions C++

LEAVE A COMMENT