Thread: stack

  1. #1
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804

    stack

    Here is a code.
    Code:
    void f1(int,int);
    int main(void)
    {
    int i,j=8;
    f1(i,j);
    return 0;
    }
    void f1(int k,int l)
    {
    int k=l+5;
    printf("%d",k);
    }
    I want to know what happens in the stack when it is executed?
    Will the steps be as follows:
    1. i,j will be pushed into the stack.
    2. Since f1 is called return address will be pushed into the stack.
    3. Local parameters k,l will be pushed into the stack.
    4. The value of k will be stored in some register.
    5. Everything will be popped i.e the k,l and the stack pointer will now point to the return address.

    I'm confused in 2,3 and 4 points above, will parameters k and l be pushed before return address or after the return address? Also the value of k will be stored in register or on the stack? Actually I read an article on wikipedia and that made me to think about it.
    Or if someone elaborate the steps, that will be of great help.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    19
    >will parameters k and l be pushed before return address or after the return address?
    After.

    >Also the value of k will be stored in register or on the stack?
    Stack.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  2. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 02:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM