Since char* a; allocates space on the stack for the character pointer, and char a[100]; Allocates space for 100 characters.
In the first case, you need to allocate some actual memory for the pointer that it points to. What happens for your failure is that a set to some arbitrary value (you do not initialize it), and when you scanf , where the data is written. If you just use a , call this type of failure number one.
If you use &a , it will write your input on the pointer itself, which will leave you with a pointer that indicates who-knows-where, which leads to failure type number two. Suppose you did not specify more characters than overflowing the pointer, which may damage the call stack, which will lead to another emergency situation (type three).
And as a tip, please do not use input functions that do not have border checks, unless you absolutely control what data is presented to them. Even with char[100] , someone can cause a stack overflow in your code by typing more characters than it will in your buffer.
I find it best to use fgets (which can restrict character reading) in combination with sscanf (although if all you get is a string, sscanf is not really needed).
source share