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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shweta LodhaPosted Feb 5, 2014, 4:22 PM
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.
SUNIL GUTTAPosted Feb 5, 2014, 8:47 AM
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-------------------------