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

  • Home
  • SEARCH
  • 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 8933843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:38:27+00:00 2026-06-15T09:38:27+00:00

Noob here and I have 2 questions. 1) When creating an array like this

  • 0

Noob here and I have 2 questions.

1) When creating an array like this int a[10], how does the system setup memory for the array? i.e. Does the system allocate ten 1-word memory contiguously (in heap?). What about char a[10]? or user defined type?

2) What about dynamic allocation? Such as int *a = new int[10]; How is this array setup in memory? (similar questions to question 1).

  • 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-15T09:38:29+00:00Added an answer on June 15, 2026 at 9:38 am

    This behaviour is not guaranteed by the C++ standard – it doesn’t even mention the stack or heap.

    But typically, when you call a function, a stack frame is pushed on to the stack that is large enough to contain all of that function’s automatic variables (and other objects, such as its return value). So if you consider the function foo:

    void foo() {
      int x;
      std::string str;
    }
    

    When this function is called, the top of the stack is pushed up so there is enough space for an int and a std::string. The size of those types are implementation-defined, with some restrictions placed on them by the standard, but you can just think of them as sizeof(int) and sizeof(std::string) bytes.

    Now when you have an array in your function, such as int a[10], the stack frame for the function will contain enough space for 10 ints, or 10*sizeof(int) bytes. This frame size is baked right into your executable – when the function is called, the stack will increase by that size.

    When you do dynamic allocation, such as int* a = new int[10], you are allocating space for 10 ints, or 10*sizeof(int), in the heap. However, you have increased the stack frame by some amount, namely sizeof(int*). The pointer object itself is stored on the stack but the ints that it points to are on the heap.

    Note that in the first example, you may wonder how the stack frame size could be baked into the executable if an std::string can have variable length. That’s because the std::string object itself has a fixed size, sizeof(std::string), but most likely does some kind of dynamic allocation to manage its internal representation – this internal representation will be on the heap.

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

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
Rails noob here. I have a rails application with (in this example) three tables.
I have some noob questions about delegate in groovy meta programming. with this line
a noob question here. I have an app that does number calculations. I support
I guess this is a noob question, but here it comes: I have a
Sorry, web noob here and I have a few questions: What exactly do web
Total noob here with javascript. I'm trying to alter a function. This is the
Total noob here. This is my first c# attempt, its a console application that
Doxygen noob here. I've searched and tried to resolve this for several hours now
c#/oop noob here. I am creating a datatable from the schema of a sql

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.