troubleshooting Question

Question regarding function stack access.

Avatar of kartik
kartik asked on
C++
3 Comments1 Solution319 ViewsLast Modified:
Consider the following code:

int foo(int p)
{
int x = 98;
int y =5;
char ch;
x= p;
cout << p;
return x;
}
void main()
{
int a = 6;
int b = foo(a);
cout<< b;
}

In this case the function stack for foo will contain:

parameter p
x
y
ch

And the stack pointer will be pointing to ch.

Now the question is:
in the function Foo, when the parameter p is accessed after ch, will the values of ch, x and y be popped out to get the value of p since stack is currently pointing to ch.
How is the value p retireved?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros