mercredi 17 avril 2019

Pointer Syntax Within Condition

After a pointer is initialized, do you have to use the * dereference operator to call the pointer in a condition?

Example:

int main()
{
    int var = 10;
    int *ptr = &var;

    if(ptr)    // does this need to be if(*ptr)  ???
    {.......}
}

And can I have a short explanation as to why?

Thank you.

Aucun commentaire:

Enregistrer un commentaire