title: When to use dereference operator for pointers C++
body: <p>I'm currently studying C++. Not in school. Using books, tutorials and practice.</p>
  
  <p>One thing that confuses me and I haven't been able to track down an answer is when to use the dereference operator (*) for pointers. For example, from C++ primer which I'm currently reading:</p>
  
  <pre><code>char *cp = get_string();
  if (cp) /* ... */    // true if the pointer cp is not zero 
  
  while (*cp) /*    ... */    // true if *cp is not the null character
  </code></pre>
  
  <p>I don't understand why in the if statement it is just cp without dereference operator and then in the while statement it uses the dereference operator. There is other examples like a mix of uses in a for loop but this is the latest example in the book that confuses me. Thanks in advance for your help.</p>
  
  <p>Summary: when do you just use variable name of pointer without the dereference and when do you use it with dereference. And how to tell difference.</p>