title: Why don't you need to specify the array size when using a pointer in C?
body: <p>Why don't you need to specify the array size when using a pointer?</p>
  
  <p>I'm new to C and trying to get a better understanding of how it works.</p>
  
  <p>If I use a pointer to declare the array greet I don't need to specify the array size.
  If I take away the pointer I then need to define the size of the array.</p>
  
  <p>Why does the compiler not need to know the size of the array to allocate when using a pointer to declare a char variable, but it does when I just declare a char variable. Bit confused on why this happens.</p>
  
  <p>Here's my example code:</p>
  
  <pre><code>int main()
  {
      char *greet; // Works fine.
  
      // char greet; // Doesn't work. Crashes when entering text.
      // char greet[]; // Doesn't work. Array size missing, won't compile.
      // char greet[20]; // Works fine.
  
      printf("Enter name\n&gt;");
      gets(greet);
  
      printf("Hello %s", greet);
  
  
  }
  </code></pre>