Jump to content
  • Advertisement

Archived

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

johnnyBravo

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

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

int * number = NULL;

if(number == NULL)
cout << "Not been set yet!";
else
cout << "number has been set";


[edited by - _the_phantom_ on October 11, 2003 2:04:26 AM]

Share this post


Link to post
Share on other sites
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
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!