Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

p=0 and p=NULL making me a boka

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi

please help me.

if p is a pointer, are p = 0; and p = NULL; the same thing??
what do the above statements do?
 
Yep... they will give you the same end result. I belive somewhere deep down in the code you will find

#define NULL 0


The reason why NULL is used instead of zero is to be more explanitory. Usually NULL is used to signify a pointer.


int isPtrNull(void* ptr)
{
return ptr == NULL;
// which is the same as
return !ptr;
// which is the same as
return ptr == 0;
}

and you can call this like

isPtrNull(nullPtr) // will return true
isPtrNull(NULL) // will return true
isPtrNull(0) // will return true
isPtrNull(non_null_ptr) // will return false

Matt
 
Like Matt said, NULL is used to assing a 0 value to a pointer.
Remember that a pointer holds a memory address.
Assigning 0 to a pointer means literally setting the pointer to point to the address 0000:0000.
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
 
And C gurantees that 0000:0000 is never a valid address.
So, in essence u are pointing it to nothing.:) Ankan.

Please do correct me if I am wrong. s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top