First, you can confuse the functionality of two: strlen () sets the length of the entire string, and sizeof () sets the size of the memory space occupied by the data type in memory.
The sizeof() function is a compile-time expression because the memory for your variable is allocated at compile time (given its dynamic writing). Thus, you get the size of the memory occupied by the data type. He does not care about the value of the variable, he just cares about the memory space.
Whereas strlen() is a function that takes a pointer to a character and continues to increase the memory from that character o, looking for the NULL character that is at the end of the line. It counts the number of characters before it finds a NULL character. Mostly indicating length.
source share