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 97233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:57:57+00:00 2026-05-10T23:57:57+00:00

In the context of C++ (not that it matters): class Foo{ private: int x[100];

  • 0

In the context of C++ (not that it matters):

class Foo{     private:         int x[100];     public:         Foo(); } 

What I’ve learnt tells me that if you create an instance of Foo like so:

Foo bar = new Foo(); 

Then the array x is allocated on the heap, but if you created an instance of Foo like so:

Foo bar; 

Then it’s created on the stack.

I can’t find resources online to confirm 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. 2026-05-10T23:57:58+00:00Added an answer on May 10, 2026 at 11:57 pm

    Given a slight modification of your example:

    class Foo{     private:         int x[100];         int *y;     public:         Foo()         {            y = new int[100];         }         ~Foo()         {             delete[] y;          }  } 

    Example 1:

    Foo *bar = new Foo(); 
    • x and y are on the heap:
    • sizeof(Foo*) is created on the stack.
    • sizeof(int) * 100 * 2 + sizeof(int *) is on the heap

    Example 2:

    Foo bar; 
    • x is on the stack, and y is on the heap
    • sizeof(int) * 100 is on the stack (x) + sizeof(int*)
    • sizeof(int) * 100 is on the heap (y)

    Actual sizes may differ slightly due to class/struct alignment depending on your compiler and platform.

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

Sidebar

Related Questions

I remember someone telling me that gzipped content is not cached on some browsers?
I have an archetype content type that previously was not folderish. Now I have
WebBrowser context menu or custom context menu does not shown over combobox. How to
Context Clojure Agents are NOT sent new values. They are sent a function which
I'm adding a custom context menu item to documents (and not folders) in a
Context I'm trying to have some "plugins" (I'm not sure this is the correct
I'm receiving this fatal error message: Using $this when not in object context. This
mysql> SELECT Ext, Pass, Name, Context FROM temp_Users WHERE temp_Users.Pass NOT IN (SELECT Pass
This is my custom model binder code for the BaseContentObject class: public class BaseContentObjectCommonPropertiesBinder
I have 1 unit test method that needs several parameters. I would like to

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.