In this ad
char * word = "whatever";
it is not an array object that is declared, but an object of a pointer that points to the first character of the string literal. And the pointer size is fixed regardless of whether it points to a scalar object, or to the first element of the array.
Note that in C ++, string literals have the type of constant character arrays. Therefore, a pointer that points to a string literal must be declared with the const
qualifier:
const char * word = "whatever";
To declare an array, you need to write
char word[] = "whatever";
Then you can really use the expression sizeof( word ) / sizeof( *word )
to count the elements in the array.
In the case of arrays, or pointers to arrays containing strings, you can also use the standard strlen function to determine how many characters are in a string (excluding the terminating zero).
For example,
#include <cstring> //... char word[100] = "whatever"; size_t n = std::strlen( word ); // n = 8
or
#include <cstring> //... const char *word = "whatever"; size_t n = std::strlen( word ); // n = 8