为什么在c ++中的if语句中使用指针及其解引用

Bra*_*don 1 c++ pointers

我正在寻找一些c ++代码,并且感到困惑if(ptr && *ptr),在这种情况下它做了什么?

// Process the data here.  We just break the data into separate pieces and 
// display it for the sake of simplicity.
char * a_pszBreak = NULL;
char * a_pszDataItem = (char*)s_aucDataBuffer;
do
{
    // The poll data is terminated by either a Carriage Return alone, or a
    // Carriage Return/Line Feed pair.
    a_pszBreak = strpbrk(a_pszDataItem, "\n\r");
    if (a_pszBreak && *a_pszBreak)
    {
        *a_pszBreak = 0;
        a_pszBreak++;
        LogPollData((const char *)a_pszDataItem);
    }
    a_pszDataItem = a_pszBreak;
} while (a_pszBreak && *a_pszBreak);
Run Code Online (Sandbox Code Playgroud)

Jac*_*ack 6

它意味着指针应指向某个东西,此外某些东西必须与0不同.

就像是 (a_pszBreak != nullptr && a_pszBrealk[0] != '\0')