小编Hil*_*l3D的帖子

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)  ???
    {.......}
}
Run Code Online (Sandbox Code Playgroud)

And can I have a short explanation as to why?

Thank you.

c++ pointers if-statement

3
推荐指数
1
解决办法
60
查看次数

标签 统计

c++ ×1

if-statement ×1

pointers ×1