Why don't you need to specify the array size when using a pointer?
I'm new to C and trying to get a better understanding of how it works.
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.
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.
Here's my example 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>");
gets(greet);
printf("Hello %s", greet);
}