If we Declare variable as follows
int i =10;
And,
If we Declare Object as Follows
Class1 obj=new Class1();
How stack and Heap Allocate work with above example ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
SUNIL GUTTARank #1,832 · 810 reputationPosted Feb 5, 2014, 3:47 AM EST
Int is value type so it goes on to store in STACK .
Where object is reference type so it goes in managed Heap .
Well if we initialize reference type like string with object then address will be stored in heap & content goes to heap .
----------------------------------Mark Answer/If it helps,Thank you-------------------------
Shweta LodhaRank #31 · 39.8K reputationPosted Feb 5, 2014, 11:22 AM EST
Please have a look at below diagram:
Int i is a value type, so it will be stored in stack
Class1 obj is a reference type, so it will be stored in heap but the reference/address of this will be stored on stack.