Interview answers verified by specialists.

Find interview questions and answers on this website:


See right interview answers on 30 common job interview questions

What does it mean when a pointer is used in an if statement?

Any time a pointer is used as a condition, it means "Is this a non-null pointer?" A pointer can be used in an if, while, for, or do/while statement, or in a conditional expression. It sounds a little complicated, but it's not.

Take this simple case:

if ( p )
{
     /* do something */
}
else
{
     /* do something else */
}

An if statement does the "then" (first) part when its expression compares unequal to zero. That is,

if ( /* something */ )

is always exactly the same as this:

if ( /* something */ != 0 )

That means the previous simple example is the same thing as this:

if ( p != 0 )
{
     /* do something (not a null pointer) */
}
else
{
     /* do something else (a null pointer) */
}

This style of coding is a little obscure. It's very common in existing C code; you don't have to write code that way, but you need to recognize such code when you see it.

Do you know that?

75% American freelancers who work from home make over $65k per year Next

Articles:

Getting payments for Freelancers
1. Read how to register and get earned money

2. Open account within 5 minPayoneer sing up to get free $25