Pointer &&

Pages: 12
alright, alright, i got it. my mistake. i've misunderstood about:
 
if (pointer1 && pointer2)

i thought if pointer1 and pointer2 is NULL then the condition will evaluate as true, like the follows:

 
if (pointer1 && pointer2) //which both of them are NULL 

will be the same like:
 
if (pointer == NULL /*true*/ && pointer2 == NULL /*true too*/)


-_-!

@LB: so what's this supposed to mean?
the null pointer constant is converted to an appropriate pointer to object with a null pointer value
closed account (z05DSL3A)
NULL is a macro that expands to either 0 or 0L, this is a null pointer constant.

A pointer points to an object of a particular type, ie int * is a pointer to an int object.

A pointer holds a value, either the address of an object or a null pointer value. A null pointer value indicates that the pointer does not point to an object.

When you compare a pointer to NULL, i.e pointer == NULL, The null pointer constant(NULL) is type converted to a pointer to an int and assigned a null pointer value. This can then be passed to the comparison operator which will return a bool with an appropriate value.

When you call if(pointer) the pointer needs to be type converted to a bool. If the pointer holds a null pointer value, the value of the converted bool is set to false (indicating that it doesn't point to an object) else it is set to true (indicating that it does point to an object).

Does that make it any clearer?
Topic archived. No new replies allowed.
Pages: 12