I am currently learning C with http://c.learncodethehardway.org/book/ and we are supposed to figure out some weird things on our own.
First of all I found this webpage that has already helped me understand some things about functions and function definitions and pointers and their use. Now the problem comes to when I see some "string" definitions.
Please correct me if these assumptions I am going to make are wrong:
char name[] = "John"; // creates an array of characters with these four letters + '\0'
A "string" is just an array of characters ending with '\0'
.
I also read that a *
before an identifier usually means that it is a pointer. For example:
int myNum = 18;
int *myNum_pointer = &myNum; // do I need the '&'?
If those assumptions are right, I don't understand what is going on here:
char *name = "John";
Is that a pointer to a string? Or is it another way of defining a string?? If so, is
char *name[] = "John";
the actual pointer to the "string"? (which is just an array of characters?).
EDIT
Reading all your answers and comments I must ask another thing. "type char *
" is a pointer to a char, right?