Use pointer-pointer to find string length:
The result of pointer-pointer is the number of elements between two pointers, but it should be noted that the two pointers to be subtracted must belong to the same space.
#include<stdio.h>
int my_strlen(char* str)
{
char* start=str;
char* end=str;
while(*end!='\0')
{
end++;
}
return end-start;
}
int main()
{
char arr[]="welcome to China";
int len=my_strlen(arr);
printf("%d\n",len);
}
The results are as follows:
Caicai's code, I hope it can help you!