Thread: Garbage values

  1. #1
    Unregistered
    Guest

    Arrow Garbage values

    why do we get garbage values if a variable isnt initialised....is there any role of pointer table in it.

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Here is a quote I found from a C-tutorial that might explain about initialized variables:
    Memory is organized in a program in different areas:

    1. The initial data area of the program. Here are stored compile time constants like the character strings we use, the tables we input as immediate program data, the space we allocate in fixed size arrays, and other items. This area is further divided into initialized data, and uninitialized data, that the program loader sets to zero before the program starts. When you write a declaration like int data = 78; the data variable will be stored in the initialized data area. When you just write int data; the variable will be stored in the uninitialized data area.
    2. The stack. Here is stored the procedure frame, i.e. the arguments and local variables of each function. This storage is dynamic: it grows and shrinks when procedures are called and they return. At any moment we have a stack pointer, stored in a machine register, that contains the machine address of the topmost position of the stack.
    3. The heap. Here is the space that we obtain with malloc or equivalent routines. This also a dynamic data area, it grows when we allocate memory using malloc, and shrinks when we release the allocated memory with the free() library function.
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User char's Avatar
    Join Date
    Apr 2002
    Posts
    31
    When you define a variable you are telling the compiler to allocate memory for it. The compiler "chooces" a memory location for that variable. That memoty location is full of 1s and 0s and all those 1s and 0s determine the value of that variable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing Floating Point Return Values
    By jason_m in forum C Programming
    Replies: 5
    Last Post: 08-15-2008, 01:37 PM
  2. Struct Values
    By Muphin in forum C++ Programming
    Replies: 5
    Last Post: 08-13-2005, 09:24 PM
  3. need some advice on displaying values
    By rEtard in forum Windows Programming
    Replies: 7
    Last Post: 06-16-2005, 09:55 AM
  4. Computing Large Values
    By swbluto in forum C++ Programming
    Replies: 8
    Last Post: 04-07-2005, 03:04 AM
  5. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM