小编Con*_*one的帖子

nullptr用于终止C风格的字符串吗?

我对A Tour of C++中的nullptr的使用感到困惑:  

int count_x(char* p, char x)
// count the number of occurrences of x in p[]
// p is assumed to point to a zero-terminated array of char (or to nothing)
{
    if (p==nullptr) return 0; 
    int count = 0;
    for (; p!=nullptr; ++p)
        if (*p==x) ++count;
    return count; 
}
// The definition of count_x() assumes that the char* is a C-style string,
// that is, that the pointer points to a zero-terminated array …
Run Code Online (Sandbox Code Playgroud)

c c++ pointers c-strings c++11

4
推荐指数
1
解决办法
342
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

c-strings ×1

pointers ×1