Thread: memory allocation

  1. #1

    Arrow memory allocation

    what is the variable declaration and variable definition.When is the memory allocated to a variable?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    A declaration lets the compiler know what type the variable is. A definition is a declaration, but a declaration isn't always a definition. A definition allocates storage for the variable and optionally gives it a value.

    int i = 0;

    Is a definition and

    extern int i;

    Is a declaration but not a definition and can be placed in the same file as the definition without any adverse effects. A variable can be defined once, but declared any number of times.

    Memory is allocated when program execution reaches the definition of a variable.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation question
    By dakarn in forum C Programming
    Replies: 11
    Last Post: 12-01-2008, 11:41 PM
  2. Dynamic memory allocation.
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-07-2006, 05:04 PM
  3. Dynamic memory allocation...
    By dicorr in forum C Programming
    Replies: 1
    Last Post: 06-24-2006, 03:59 AM
  4. C memory allocation to c++
    By markucd in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2005, 05:56 AM
  5. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 08:36 AM