void EventsStack::push(Event *e){
EventNode *q = new EventNode();
q->data = e;
q->next = _top;
_top = q;
}
void main() {
EventsStack eventStack;
Event e1(1);
eventStack.push(&e1);
Event e2(2);
eventStack.push(&e2);
}
First question: when I do
eventStack.push(&e1);
am I sending the ADDRESS of e1 to the push function, and the push function receiving it as a pointer? as if I am doing:
Event *e = 1000 (1000 is the offset (address) of e1 for example on the stack)
?
Second question: I am asked to illustrate the stack upon running the main function. When I get to the line
eventStack.push(&e1);
does a 4 byte return address and a 4byte pointer to e1 get allocated as the function’s activation frame or in this situation there is no activation frame since eventStack is an object of the class EventsStack and the push is one of its’ member functions?
Regarding your first question, yes: the
&operator yields the memory address of your Event.As to your second question, well, it’s complicated. The description you made seems to indicate an underlying confusion as to how the stack works. I’d strongly recommend going over some introductory material on the topic, it’s going to leave you with a much stronger understanding.
You’ll be able to answer your own question a few hours from now if you go Google a bit :).