title: Segmentation fault (core dumped) in my pointer code c++
body: <p>I am currently making a program that aims to update student data using pointers and structures, but I get a Segmentation fault (core dumped) error. This is the code that I use:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct Person
  {
      char name[64];
      int age;
      char gender[12];
  };
  
  
  int main()
  {
  
      int loop;
      cout &lt;&lt; "how many student to input: ";
      cin &gt;&gt; loop;
      struct Person *ptr[loop], d[loop];
  
      for(int c = 1; c &lt; loop; c++){
          Person *ptr[c], d[c];
          ptr[c] = &amp;d[c];
        }
  
      for (int a = 1; a &lt;= loop; a++){
      cout &lt;&lt; "Name: ";
      cin &gt;&gt; (*ptr[a]).name;
      cout &lt;&lt; "Age: " ;
      cin &gt;&gt; (*ptr[a]).age;
      cout &lt;&lt; "Gender: ";
      cin &gt;&gt; (*ptr[a]).gender;
      }
  
      cout &lt;&lt; "\nDisplaying Information." &lt;&lt; endl;
      for (int a = 1; a &lt;= loop; a++){
      cout &lt;&lt; "Name: " &lt;&lt; (*ptr[a]).name &lt;&lt; endl;
      cout &lt;&lt;"Age: " &lt;&lt; (*ptr[a]).age &lt;&lt; endl;
      cout &lt;&lt; "Gender: " &lt;&lt; (*ptr[a]).gender&lt;&lt;endl;
      }
  
      system("pause");
      return 0;
  }
  </code></pre>