"Sizeof" and "strlen" find the difference between array length

1. sizeof(str) calculates the total size of the array in bytes

#include<stdio.h>
int main()
{
    
    
	char str[] = "hello CSDN";
	printf("%d\n", sizeof(str));
}

Insert picture description here
The output result is 11

2. Strlen is to find the length of the
string. Find the end of the string'\0', how many characters appear before the'\0', the length is

#include<stdio.h>
int main()
{
    
    
	char str[] = "hello CSDN";
	printf("%d\n", strlen(str));
}

hello space CSDN \01 2 3 4 5 6 7 8 9 10

The output result is 10

Guess you like

Origin blog.csdn.net/qq_45658339/article/details/108695970