Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:18+00:00 2026-06-12T08:13:18+00:00

Possible Duplicate: What and where are the stack and heap? With regard to the

  • 0

Possible Duplicate:
What and where are the stack and heap?

With regard to the basic concepts of memory layout in a c program, I understand the that:

  • The language uses two primary data structures stack and heap.
  • Stack is created to store the local variables and book keeping data of subroutines
  • Heap is created to store the dynamically allocated variables of the program
  • Heap is of variable length in nature.(Not very sure on stack)
  • Normally it is the responsibility of the compiler/Language to request the OS to create these data structures before the execution.

Questions

  • What is the initial size with which a stack/heap is created? and who decides it?
  • Wherein physical memory are they are created? I see a general description as “Stack is created in the top-level-address and the heap at the low-level-address” Please elobarate this
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:13:19+00:00Added an answer on June 12, 2026 at 8:13 am

    “Stack is created in the top-level-address and the heap at the
    low-level-address” Please elobarate this

    This is a myth. It may have a basis in historical truth. It might sometimes resonate with things you see in real life. But it is not literally true.

    It’s easy enough to explore, though:

    #include <stdlib.h>
    #include <stdio.h>
    
    void check(int depth) {
        char c;
        char *ptr = malloc(1);
        printf("stack at %p, heap at %p\n", &c, ptr);
        if (depth <= 0) return;
        check(depth-1);
    }
    
    int main() {
        check(10);
        return 0;
    }
    

    On my machine I see:

    stack at 0x22ac3b, heap at 0x20010240
    stack at 0x22ac0b, heap at 0x200485b0
    stack at 0x22abdb, heap at 0x200485c0
    stack at 0x22abab, heap at 0x200485d0
    stack at 0x22ab7b, heap at 0x200485e0
    stack at 0x22ab4b, heap at 0x200485f0
    stack at 0x22ab1b, heap at 0x20048600
    stack at 0x22aaeb, heap at 0x20048610
    stack at 0x22aabb, heap at 0x20048620
    stack at 0x22aa8b, heap at 0x20048630
    stack at 0x22aa5b, heap at 0x20048640
    

    So, the stack is going downwards and the heap is going upwards (as you might expect based on the myth), but the stack has the smaller address, and they are not growing toward each other (myth busted).

    Btw, my check function is tail-recursive, and on some implementations with some compiler options you might see the stack not moving at all. Which tells you something about why the standard doesn’t mandate how all this works — if it did it might inadvertently forbid useful optimizations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What and where are the stack and heap Where is heap memory
Possible Duplicate: Syntax highlighting code with Javascript I have noticed that Stack Overflow uses
Possible Duplicate: C Array Instantiation - Stack or Heap Allocation? When dynamically allocating a
Possible Duplicate: Why would you ever want to allocate memory on the heap rather
Possible Duplicate: Stack,Static and Heap in C++ Hi guys, I am currently preparing for
Possible Duplicate: Fields of class, are they stored in the stack or heap? I
Possible Duplicate: How is heap and stack memories managed, implemented, allocated? Hi, my question
Possible Duplicate: C++ Which is faster: Stack allocation or Heap allocation What is more
Possible Duplicate: Malloc or normal array definition? We learn that there is dynamic memory
Possible Duplicates: Why are two different concepts both called “heap”? What's the relationship between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.