Store double in memory

Hi,

I am working on a practical for a university topic and have got stuck when asked to store the value of a double in memory and then return that value from memory back into a double.

This is what I'm currently trying to do:

double *p = stack.pop(); //store top value of stack into memory

stack.push(*p); //Push value stored in memory back into stack

Can anyone point out where I am going wring?

Cheers,
JD

Well, stack.pop returns the value of the popped element.
If that's a pointer in your case that's fine however, if the stack stores pointers you should push back the pointer itself and not the value of the pointer
stack.push(p);


But I honestly don't understand why you would use a pointer.

1
2
3
4
std::stack<double> st;
st.push(32.03);
double val = st.pop();
st.push(val);


I also don't understand what you mean by
[...] store the value of a double in memory [...]

Last edited on
Topic archived. No new replies allowed.