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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:16:11+00:00 2026-05-25T01:16:11+00:00

In C# classes are stored in heap, and structs are stored in stack. Does

  • 0

In C# classes are stored in heap, and structs are stored in stack.

Does in C++ classes and strucs are stored in the same way (assuming I create my classes and structs statically, and every member of class or struct is not allocated by new) ?

Please explain this using snippet of code below:

class B
{
int b;
}

class C
{
int c;
}

class A
{
B b;
C c;
int x;
}

struct SB
{
int sb;
}

struct SC
{
int sc;
}

struct SA
{
SB sb;
SC sc;
int x;
}

void main()
{
A a1;
A *a2 = new A;

SA sa1;
SA *sa2 = new SA;
}
  • 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-05-25T01:16:12+00:00Added an answer on May 25, 2026 at 1:16 am

    There is no (necessary) difference in how structs are stored vs. how classes are stored. In fact, the only difference between structs and classes in C++ is that struct members are public by default, and class members are private by default.

    Like any other kind of object, an object of class or struct type has a storage duration which is determined by how it’s created.

    An object declared inside a function has its lifetime limited to the enclosing block; this is typically implemented by storing it on the stack.

    An object declared outside a function, or with the static keyword, has a lifetime that extends over the entire execution of the program; this might be implemented by storing it in the data segment.

    An object allocated by a new operator (or malloc() call) exists until it’s deleted (or free()ed); such objects are allocated in the “free store”, sometimes informally referred to as “the heap”.

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

Sidebar

Related Questions

Possible Duplicate: Why are structs stored on the stack while classes get stored on
Originally my classes( .as) and project ( .fla) were stored in the same directory.
I have two related classes which share a common interface and are both stored
I have the following 3 rails classes, which are all stored in one table,
I have a set of XSDs from which I generate data access classes, stored
Many classes in Cocoa/Cocoa Touch have the NS prefix. What does it mean?
Sometimes I want to emulate stored data of my classes without setting up a
I am using the Microsoft.SqlServer.Management.Smo classes to script out SQL scripts for stored procedures,
i've added to my MySQL database, 2 stored procedures, then generated data access classes
I have the class name stored in a property file. I know that the

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.