Question: Compare const and non-const pointers. Is the comparison legal? Any special care for such comparison. Thanks.

Answer: 
A pointer to `T` can be implicitly converted into a const pointer to `T`; similarly, a pointer to `T` can be implicitly converted into a pointer to `const T`. The compiler will do either of those conversions, or both, as needed when you try to compare a pointer to a const pointer. There's nothing there that's any more risky than comparing two non-const pointers or two const pointers.
The purpose of const as in 

> 
> const char\* p
> 
> 
> 

is to promise that you will not change it. In theory, a non-const pointer should never be pointing at the same location in the same code, as a matter of good coding practice that is. In practice, you may end up making something const because it makes your life easier, but it is not really a true const conceptually. In that case you might need to compare. As was mentioned, depending on what compiler you are using and what settings it has, it may or may not like such a comparison. Just in case it might not, force a cast to a non-const before comparing if this is bothering you, like this, for example:

> 
> if ((char\*)const\_p == non\_const\_p)
> 
> 
>