Difference of sizeof between char* x and char x[]

c, char, sizeof

Solution

The sizeof an array type is the size the array takes up. Same as `sizeof("xxxx")`.

The sizeof a pointer type is the size the pointer itself takes up. Same as `sizeof(char*)`.

Problem

I know some difference between char* and char[]. `char x[] = "xxxx"` Is an array of chars; `char *y = "xxxx"` is a pointer to the literal (const) string; And `x[4]=='\0'`, and `*(y+4) == '\0'` too. So why `sizeof(x)==5` and `sizeof(y)==4`?

Original source

Related problems