Use the last character of the string to be'\0' to manipulate the string

Use the'\0' feature at the end to find the length of the string to achieve strlen;

int len =0;
char str[]="hello";
char*p =str;
while(*p)
{
  len++; //计算字符串的长度
  p++;    //将指针指向字符串的结尾'\0'
}

for(p--;p-str>=0;p--)
puts(p);

 

Guess you like

Origin blog.csdn.net/modi000/article/details/114044688