About sizeof strlen and use of

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

  1. Operator is used to calculate the number of bytes, comprising (\ 0) in the calculation of the size of a string array
  2. Calculating the size at compile time, the parameter can be an array, a pointer, type, object, functions, and so on.

strlen

  1. Is a function for testing string length does not include (\ 0)
  2. 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:

The summary is not too detailed, I hope you can be supplemented!

Guess you like

Origin www.cnblogs.com/fanhua666/p/11445319.html