Thread: quick RAM allocation question

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    162

    Question quick RAM allocation question

    Hi,
    I was wondering something. Is the memory of the variables in a function freed after the function returns? Not static or pointer variables, just something like int number;. I assume it is, but I realized I never actually knew. Just checking. Thanks.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Yes. Local variables (stack variables) are freed. Pointers, too, are freed, but not what they point at. E.g.:

    Code:
    void f(){
      int *p = new int[50];
    }
    The actual pointer (probably 4 bytes) is deallocated. The array it points at (probably 200 bytes) is not (which is why you use delete[]).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  2. Quick Question on File Names and Directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 02:54 AM
  3. * quick question *
    By SavesTheDay in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 06:58 PM
  4. dynamic allocation question
    By vale in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 04:23 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM