Archived

This topic is now archived and is closed to further replies.

johnnyBravo

How to check if my pointer value has been set yet....

Recommended Posts

Chacha    138
the_phantom is correct.

If you declare a pointer, then it initially points to nothing. A pointer that points to nothing is called a ''NULL'' pointer. So to check whether a pointer actually points to something, you simply check whether that pointer is NULL or not, like the_phanton did.

Share this post


Link to post
Share on other sites
Sneftel    1788
quote:
Original post by chacha
If you declare a pointer, then it initially points to nothing. A pointer that points to nothing is called a ''NULL'' pointer. So to check whether a pointer actually points to something, you simply check whether that pointer is NULL or not, like the_phanton did.

Careful there. When you declare a pointer, it doesn''t initially point to NULL. It points to some random memory location that is most likely outside of your program''s memory area (IIRC, on MSVC debug it''s usually 0xC4C4C4C4) and thus will make the program crash if accessed. That''s why it''s important to always initialize your pointers to NULL (or 0) when declaring them.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Chacha    138
quote:
Original post by Sneftel
quote:
Original post by chacha
If you declare a pointer, then it initially points to nothing. A pointer that points to nothing is called a ''NULL'' pointer. So to check whether a pointer actually points to something, you simply check whether that pointer is NULL or not, like the_phanton did.

Careful there. When you declare a pointer, it doesn''t initially point to NULL. It points to some random memory location that is most likely outside of your program''s memory area (IIRC, on MSVC debug it''s usually 0xC4C4C4C4) and thus will make the program crash if accessed. That''s why it''s important to always initialize your pointers to NULL (or 0) when declaring them.


How appropriate. You fight like a cow.

Yes, thanks for correcting me Sneftel.

Share this post


Link to post
Share on other sites