Since you tagged the question with both "C" and "C++", I will answer the question for both languages.
The statement
s = "cool man army";
where s
is of type char *
is only valid in C, not C++. In C++, the variable s
must be of type const char *
, because the string literal decays to that type. Only in C does the string literal decay to the type char *
. However, in both languages, the string literal is read-only, even if it is not const
in C.
On modern 64-bit platforms, pointers are normally 64-bit, that is why sizeof(s)
is 8 bytes (which is equivalent to 64 bits). The string literal "cool man army"
however is an array and not a pointer (and also does not decay to one when used with the sizeof
operator). Therefore, sizeof("cool man army")
is the actual length of the array (including the terminating null character), which is 14.
EDIT: Meanwhile, the C++ tag has been removed from the question. However, since it was not the OP who did that, I will not remove my comments about C++ from my answer.