where is memory for struct allocated?
where is memory for class-object allocated?
I replied for struct in stack and for class-object in heap.
THen he asked if class has struct member variable what
happens.class on heap and what about struct in that class?
couldnt ans :( :-?

Answers were Sorted based on User's Feedback



where is memory for struct allocated? where is memory for class-object allocated? I replied for st..

Answer / rajanikanth

variable: value type lives on the stack, reference type lives on the stack as a pointer to somewhere in heap memory where the actual memory lives
class/struct-field: value type lives inside the class, reference type lives inside the class as a pointer to somewhere in heap memory where the actual memory lives.

Is This Answer Correct ?    6 Yes 1 No

where is memory for struct allocated? where is memory for class-object allocated? I replied for st..

Answer / vishwa

Both are allocated in heap.
Also if any structure is declared in a function, the
function stack creates a heap from the stack. so these
structures in function allocates in heap.

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More OOPS Interview Questions

Difference between over loading and over ridding?

12 Answers   CTS, Patni, Softvision Solution,


i got a backdoor offer in process global,Bangalore..Can i work with it?

0 Answers  


Explain polymorphism? What r the types of polymorphism? pls give examples?

4 Answers   HCL,


Why is oop better than procedural?

0 Answers  


what is object slicing?

9 Answers   L&T, Wipro,






What is constructor overloading in oop?

0 Answers  


program for insertion ,deletion,sorting in double link list

0 Answers  


What is encapsulation with example?

0 Answers  


what is a virtual class?

5 Answers   Cap Gemini, IBM, Infosys, Trinity Technologies,


How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.

4 Answers   NIIT, TCS,


can main method be overloaded...??? How..????

2 Answers   Satyam,


what is different between oops and c++

0 Answers   IIT,


Categories