I am trying to understand pointers in C but I am currently confused with the following:
char *p = "hello"
This is a char pointer pointing at the character array, starting at h.
char p[] = "hello"
This is an array that stores hello.
What is the difference when I pass both these variables into this function?
void printSomething(char *p)
{
printf("p: %s",p);
}
For cases like this, the effect is the same: You end up passing the address of the first character in a string of characters.
The declarations are obviously not the same though.
The following sets aside memory for a string and also a character pointer, and then initializes the pointer to point to the first character in the string.
While the following sets aside memory just for the string. So it can actually use less memory.