sizeof(data)
returns the size in bytes of the type of the object data
, a char*
in this case, i.e. it returns exactly how many bytes it takes to store a character pointer but not the actual character array. The char*
type does not store the size of the character array to which it points, you must store that size separately in an size_t
(see 1).
void* memset( void* str, int ch, size_t n);
n
is the number of bytes starting from the location str
that will all be set to the value ch
. The size in bytes of an array of type T
having n
elements is returned (in a size_t
) by sizeof(T[n])
.
1: size_t
behaves exactly as an unsigned int
but may have different numerical capacity, it's maximum is the most number of bytes you can allocate to an array.