关于c++字符串的while(*temp++)

首先,上一段代码

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关键字

原文地址:https://www.cnblogs.com/audi-car/p/4770038.html