char anything[] is a pointer? Not really.
The actual literal type "hello world" is const char[12] . (Note the extra element for the NUL terminator).
But when it is passed to the function, this type decays to const char* .
So get_string_size returns sizeof(const char*) , which is 8 on your platform (ie sizeof a char* ), but sizeof("hello world") is equal to sizeof(const char[12]) , which is 12, so how sizeof (char) is defined by the C 1 standard.
get_string_length returns the position of the first NUL terminator, starting with the pointer passed to it.
Finally, note that you should use %zu as the format specifier for the returned sizeof : technically, the behavior printf("%d\n", sizeof("hello world")); equals undefined.
Bathsheba Feb 06 '17 at 13:34 on 2017-02-06 13:34
source share