memory allocation

This is a discussion on memory allocation within the C Programming forums, part of the General Programming Boards category; what is the variable declaration and variable definition.When is the memory allocated to a variable?...

  1. #1
    Unregistered
    Guest

    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
    Posts
    9,796
    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.

    -Prelude
    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, 10: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, 04:56 AM
  5. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 07:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21