Thread: No one has been able to answer this yet!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    2

    No one has been able to answer this yet!!

    Hi, I haven't been able to find a satisfactory answer yet!, but what would this code do?



    Code:
    void main()
    {
        int a;
    
        a = foo();
    
        printf("%d",a);
    
    }
    
    
    int foo()
    {
    
       int *p;
       
       p = malloc(1*sizeof(int));
    
       *p = 5;
    
       return (*p);
    
    }
    So I guess the idea is , what happens to "p" at the termination of the function call? since its a stack variable, it gets popped, but the malloc'd memory is on the heap, which still persists, I think? and since you're returning the dereferenced variable, it should be good, right?
    Last edited by squadeek; 06-14-2006 at 09:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. One quick question...
    By Kross7 in forum C++ Programming
    Replies: 10
    Last Post: 04-13-2007, 09:50 PM
  3. Tic Tac Toe program...
    By Kross7 in forum C++ Programming
    Replies: 12
    Last Post: 04-12-2007, 03:25 PM
  4. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  5. code help :)
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 02-28-2002, 01:12 PM