Thread: function calls

  1. #1
    Registered User
    Join Date
    Sep 2012
    Location
    germany
    Posts
    1

    Post function calls

    I have a question regarding function calls. If function with variable(s) calls another one, which calls another one ...etc, like a chain of function calls. Where and how are the memories(of variable for instance) stored/managed for each function calls? Are they stored in a single stack automatically? thank you very much in advance.

    example code:
    Code:
    int func1 (int x){
        int a = x;
        a += func2(x);
        return a;
    }
    
    int func2 (int x){
        int a = x;
        a += func3(x);
        return a;
    }
    
    int func3 (int x){
        int a = x;
        a += func4(x);
        return a;
    }
    and so forth...
    PS: I'm new to programming, just taking interest lately

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    All local variables will be stored on the stack.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Call stack - Wikipedia, the free encyclopedia
    You're welcome to ask for clarification, if you can't understand any part of that page.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    Yep, your thinking is correct that it's a 'single' stack as well.
    Check out my programming / algorithm blog @ http://www.swageroo.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and function calls inside a function
    By lexitron in forum C Programming
    Replies: 1
    Last Post: 12-03-2011, 05:43 PM
  2. Replies: 19
    Last Post: 09-08-2011, 07:56 AM
  3. arg...function calls
    By 2fastwrx in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2004, 10:55 PM
  4. Function calls
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 07-18-2002, 04:01 PM
  5. Function calls
    By Zewu in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2002, 04:44 PM