Whats the difference between char * and char []?
This questions usually presents code such as the following and asks what is different, or why it is not the same: char *p = “abcde”; // LINE A char q[] = “ABCDE”; Well, they are not the same. p is a pointer, a variable in its own right with its own memory, that is being initialized to point to the address of “abcd”, an unnamed string literal. If you could break it down into steps, you might have: char *p; p = “abcde”; whereupon p will be pointing at the location of where the a is. With q, it is actually the name for an array, specifically a 6 character array. It is as if it were declared as: char q[] = { ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘\0’ }; Here q does not point at the array of chars, it actually is the beginning location of the array of chars, 6 of them. With those things in mind, to be clear, note that p is of type char * and q is of type char [6]. In fact, the pointer can point at the array: p = q; // ok, p points at the location holding the A, aka &q[0] we can even write that: p = &q[0