Thread: malloc

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    17

    malloc

    if I have a function like this:

    Code:
    void function(int* parameter){
    int * variable;
    variable = parameter;
    }
    do I have to make a malloc for variable?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Use the stack.
    Code:
    void function(int *param)
    {
        int val = *param;
    }
    
    int main()
    {
        int n = 5;
        function(&n);
    
        return 0;
    }
    gg

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >do I have to make a malloc for variable?
    No.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc + segmentation fault
    By ch4 in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 03:46 PM
  2. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 12:26 PM
  3. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 05:37 AM
  4. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM
  5. malloc always setting length of 8?
    By Zarkhalar in forum C++ Programming
    Replies: 7
    Last Post: 08-01-2004, 11:36 PM