title: C struct pointer accessing fields
body: <p>I've read that if we have a pointer to a struct type object we can't access the object field by using the asterisk (*) but we need to use this -> (like an arrow sign).</p>
  
  <p>Now although I read about it I didn't understand why we can't use the asterisk, I'll try to provide a code example and a picture of how I visualize a struct in memory to help you understand what is preventing me from understanding this topic.</p>
  
  <p>Okay, so here's our code :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  typedef struct MyStruct
  {
      char c1;
      char c2;
  } MyStruct;
  
  int main()
  {
      MyStruct s1; // Let's assume s1's address is 0x34A
      s1.c1 = 'A';
      s1.c2 = 'B';
      printf("s1 c1 is %c and c2 is %c.\n", s1.c1, s1.c2);
  
      MyStruct *p = &amp;s1; // Declaring our pointer to point to s1 address, so p points to 0x34A
      printf("s1 c1 is %c and c2 is %c.\n", p-&gt;c1, p-&gt;c2); // I know this is the valid way
      printf("s1 c1 is %c.\n", *p.c1); // I don't understand why this would be invalid
      return 0;
  }
  </code></pre>
  
  <p>Now let me try to explain why I don't understand why this syntax is invalid.
  So p is pointing to the address of s1 which is 0x34A and as I see it this is how I see s1 in memory:</p>
  
  <p><img src="https://i.stack.imgur.com/hX3m3.png" alt="enter image description here"></p>
  
  <p>So what I imagine it as in memory is that s1 has it's own address of course which in our example is 0x34A and it points to c1 address in memory which is followed up by c2 address.
  So when I do this :</p>
  
  <pre><code>printf("s1 c1 is %c.\n", (*p.c1)++, *p.c2);
  </code></pre>
  
  <p>I think of it as I'm accessing the value that is inside the pointer address by our pointer so we're accessing the value which is c1.</p>
  
  <p>But as I said it's invalid and I just breaking my head trying to understand why, I've tried to read about it but couldn't really put the finger on the answer that will satisfy me on why really, so I've provided the code example and the picture so you could get into my head and try and see why I'm thinking wrong here.</p>