The size of a pointer is always the size of the pointer itself, not what it points to. That's because sizeof
is mostly a compile-time operator (the result is evaluated by the compiler) and the compiler can't know what a pointer might point to at run-time.
As for sizeof *title
it's the same as sizeof title[0]
which is a single char
. And the size of a char
is 1
(it's specified to always be 1
by the way, no matter the actual bit-width).
Lastly about sizeof "VP"
. In C all literal strings are really arrays of characters, including the terminating null character. So the literal string "VP"
is an array of three characters, hence its size is 3
.
To make the answer a little bit more complete, I say that the sizeof
operator is mostly compile-time. That of course can't be true for variable-length arrays, where the compiler must insert code to store the actual size of the array in a way that it can be fetched at run-time. If the array decays to a pointer, then all you have is the pointer and again sizeof
returns the size of the pointer itself.
And a note about string literal arrays. While they are technically non-constant arrays, they still can't be modified. Attempting to modify a string literal leads to undefined behavior. Literal strings are thus, in effect, read-only.