首先,上一段代码

static bool reverse_str(const char *str)
{
    const char *temp=str;
    while(*temp++);
    temp-=2;        //指针返回到字符串的末尾
    while(str<temp)
    {
        if (*str!=*temp)
        {
            return false;
        }
        str++;
        temp--;
    }
    return true;
}

其实它完成的就是回文字符串的 判断。

里面的一句代码:

const char *temp=str;
    while(*temp++);
    temp-=2;        //指针返回到字符串的末尾

这里的

temp-=2;

就是为了回到字符串的末尾字符。这里注意一下就写那个了。

另外,写代码注意规范性

注意函数前面的static关键字

以及函数参数前面的const关键字

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
相关资源
相似解决方案