Say i have a object in dynamic memory (new) and inside one of its functions, it has
int Obj1::Add(int a, int b)
{
int c = a + b;
return c;
}
Is c (and a and b…) on the stack ? or in dynamic memory with my object. Just curious 🙂 Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All of those will be on the stack.
aandbare passed parameters so, even if the originals were in the heap, a copy would be made on the stack. If you were passing by reference, it may be a different matter since the thing actually sent across (“under the hood”) would be more of a pointer to the original.For
c, since it’s a local variable, it’s on the stack too.That’s of course assuming your implementation even uses a stack, and that optimisation hasn’t just stashed them into registers. It’s really totally up to the implementation.