I have the code below:
static char *name[] = {
"January",
"February",
"March",
};
printf("%s", name[0]);
When I passed printf with name[0], it prints January. But shouldn't it print the address of January, since the array above stores a pointer to January?
printf's%sformat wants a pointer. Yournamearray is an array of pointers. Soname[0]is a pointer, and everyone's happy. (And, more specifically,%swants, andname[0]is, a pointer tochar, that points to the beginning of a valid, null-terminated string.)%p.name[0]stores a pointer to the first character of a non-modifiable, anonymous array ofcharthat is the string literal"January".