title: Why null pointer able access member array of a structure in C?
body: <p>I'm confused about how null pointer access a structure member in c language. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct A
  {
      int i;
      char str[30];
  };
  
  int main()
  {
      struct A *p = NULL;
  
      printf("accessing str with null pointer %d\n", p-&gt;str);
      printf("accessing i with null pointer %d\n", p-&gt;i);
      printf("accessing str[0] with null pointer %d\n", p-&gt;str[0]);
  
      return 0;
  }
  </code></pre>
  
  <p>In above example, only first printf is executing. Other printf are crashing the program. I thought all of them would crash the program. but why p->str(array member) isn't causing any problem? From my search I found those questions <a href="https://stackoverflow.com/questions/10904951/null-pointer-able-to-access-class-member-function">NULL pointer able to access class member function</a> and <a href="https://stackoverflow.com/questions/669742/accessing-class-members-on-a-null-pointer">Accessing class members on a NULL pointer</a> which is helpful but questions are related with member function. Can someone help me to understand, how null pointer access work for member variables (array and non-array).</p>