1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regarding infinite loop and heap memory

Discussion in 'C' started by SunilC, Sep 25, 2005.

  1. SunilC

    SunilC New Member

    Joined:
    Sep 25, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I have couple of questions.

    My friend put across this question to me asking whether the following piece of code would result in an infinite loop...
    while(1)
    {
    int i;
    }

    I guess it doesnt result in an Infinite loop but instead keeps on getting executed until the entire memory gets exhausted.. Could I please get a validation??

    And

    Could i get to know what heap memory means?? Does that refer to data segment? (if yes could i plz get to know how size of data segment is determined)??
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    First of all I would like to welcome you to go4expert programming forum
    Code:
    while(1)
    {
      int i;
    }
    
    This will be infinite loop.

    It will defintely result in an infinite loop for a simple reason that the variable being declared is removed from the memory when it goes out of scope and so this will not be what you are thinking.

    A heap is a specialized tree-based data structure. Its base datatype (used for node keys) must be an ordered set.

    Let A and B be nodes of a heap, such that B is a child of A. The heap must then satisfy the following condition (heap property):

    key(A) ≥ key(B)

    Data segment is something related to compiler as far as I can think of and is not related to heap memory.
     
  3. SATYAN JANA

    SATYAN JANA New Member

    Joined:
    Jul 31, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Kolkata
    One thing I'll add,-
    There will be memory allocation from stack-memory. The heap memory has nothing to do here.
     
    Last edited: Sep 27, 2005

Share This Page