title: Manipulating values of struct data type with a function
body: <p>I'm learning about struct types in C++ and I tried to write a function that would change the values of the members of a struct type variable. 
  However, it produces an unexpected output and I can't figure out why this is happening. 
      /<em>Program to test struct types</em>/</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  struct myStruct
  {
      string a;
      string b;
      int c;
      float d;
  };
  
  void assignValues(myStruct myobj)
  {
      myobj.a = "foobar";
      myobj.b = "Foo Bar";
      myobj.c = 12;
      myobj.d = 15.223;
  }
  int main()
  {
      myStruct x;
      cout &lt;&lt; x.a &lt;&lt;endl;
      //x.a = "Hello world";
      //x.b = "This is C++";
      //x.c = 10;
      //x.d = 13.1332;
      assignValues(x);
      cout &lt;&lt; x.a&lt;&lt;endl;
      cout &lt;&lt; x.b &lt;&lt; endl;
      cout &lt;&lt; x.c &lt;&lt; endl;
      cout &lt;&lt; x.d &lt;&lt; endl;
  }
  </code></pre>
  
  <p>If I use the individual assignment statements, (that I have commented out in the code) instead of the assignValues() function, I get the expected output. </p>
  
  <p>PS: The values I expected for the output are as follows:
  foobar,
  Foo Bar,
  12,
  15.223</p>