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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:02:29+00:00 2026-06-17T22:02:29+00:00

It is said that value types are stored in stack. But what happens when

  • 0

It is said that value types are stored in stack. But what happens when we declare a value type with new?
For example

int a;

is stored in stack, but

int b=new int();

Where does b is stored? Heap or stack? It’s confuses me. It’s like a reference, but it’s a value type.

  • 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-17T22:02:31+00:00Added an answer on June 17, 2026 at 10:02 pm

    It is said that value types are stored in stack

    This is said frequently but it is obviously false. When you make an array with 100 ints, do those ints live on the stack, or the heap?

    The idea that the lifetime of storage has something to do with the type of the storage is simply false. The correct statement is that variables of value type that are of known short lifetime can be allocated from short-term storage, which sounds pretty obvious when you put it that way.

    Make sure you’re clear on that: it is simply false that int i; means "allocate i on the stack". It means "allocate storage for i"; if that storage lifetime is known to be short then it can be allocated on the short term store. Otherwise it is allocated on the long-term store.

    But what happens when we declare a value type with new?

    You’re thinking that "new" causes new storage to be allocated off the heap. It does not. Think of "new" as meaning "obtain storage and then invoke a constructor".

    The storage obtained for a class type is always on the heap because the lifetime of the class data is not known to be short. The storage obtained for a value type is documented as being on the stack, and then the value is copied to its final destination, which might be on the stack or the heap. However that allocation and copy can be copy-elided if the compiler can determine that it is safe to do so.

    Here are some articles that will help:

    http://blogs.msdn.com/b/ericlippert/archive/2010/09/30/the-truth-about-value-types.aspx

    https://ericlippert.com/2010/10/11/debunking-another-myth-about-value-types/

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

Sidebar

Related Questions

Somewhat academic question, but: How do value types like Int actually work ? I've
We know that int is a value type and so the following makes sense:
On the manual page; http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html It is said that Returns the value generated for
Somebody said that when your PHP code and application use global variables then it
It is said that When an interrupt is sent by the PIC, the PIC
It is often said that in C++11 it is sane to return std::vector by
It is said that fork system call creates a clone of the calling process,
In manual it said that InnoDB has row-level locking, so why if I select
Before someone said that I did not read I may say that I read
in this answer he said that i can use RIA services while creating my

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.