int count_x(const 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!=0; ++p)
if (*p==x)
++count;
return count;
}
p is a pointer. The const means that the pointer cannot be modified. But in the for loop, there is ++p, which means the pointer is being iterated over/incremented to access the values *p
There’s a contradiction there - p cannot be modified yet it is being incremented/modified?