Advertisement

stupid pointer problem

Started by December 30, 2000 09:37 PM
4 comments, last by Julio 24 years ago
alright, I have tried for a while now trying to set a float pointer value of another float pointer. here''s some psuedo code: float *value; float *pointer; pointer=&value // somehow, also tried memcpy I''ve tried varouse methods, even ones that I''ve used before. but I always get a compile error or a runtime error. any easy (well obviously) way to do this? Thanks HHSDrum@yahoo.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
If you''re trying to have pointer equal to the address of value do this:

float Variable = 2342;
float *Value = &Variable,
*Pointer;

//Always initialize your pointers to something!

Pointer = Value;

If you''re trying to get Pointer to pointer to Value do this:

float Variable = 254;
float *Value = &Variable,
**Pointer;

Pointer = &Value

Hope this helps
Advertisement
yup, just what I was looking for, thanks.

HHSDrum@yahoo.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
#include int main(){	float * a = new float;	float * b;	*a = 3.333f;	b = a;	cout << *b << endl;	// return success	return 0;} 
People forget to mention WHY you should init pointers when you declare them. If you declare them when you init them, then you know if the pointer points to something legal.

Say you do this:

int* Pointer=NULL;
or
int* Pointer=0;

Then in your program you can do this:

if(Pointer!=NULL) or if(Pointer)
{
It''s safe to use.
}
else
{
Don''t even think about using it.
}

Everytime you delete dynamicly allocated memory you can set your pointer to zero or NULL. so that the next time you need to process that pointer, you''ll know if you can use or delete it.
I''m initializing all of my pointers. I just had trouble converting values between them.

HHSDrum@yahoo.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

This topic is closed to new replies.

Advertisement