In the study we found that the relationship between the C language and sizeof strlen is not very clear, to sum up the difference between the two today:
sizeof
- Operator is used to calculate the number of bytes, comprising (\ 0) in the calculation of the size of a string array
- Calculating the size at compile time, the parameter can be an array, a pointer, type, object, functions, and so on.
strlen
- Is a function for testing string length does not include (\ 0)
- Size calculated at run time, the parameter is the character pointer.
#include <stdio.h>
int main(void)
{
int size1, size2;
char a[] = "hello";
size1 = sizeof(a);
size2 = strlen(a);
printf("%d %d", size1, size2);
return 0;
}
Generally used in the array sizeof
result: