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

write a program to find the largest of two numbers without using for,while,switch,if else, conditional operator and do while using c++ pgmng language

3 Answers   Satyam,


Why do we use polymorphism in oops?

0 Answers  


How long to learn object oriented programming?

0 Answers  


The expansion of GNU

3 Answers  


Why oops is important?

0 Answers  






what is the difference between a package and a software?

3 Answers  


What is encapsulation and abstraction? How are they implemented in C++?

0 Answers   Agilent, ZS Associates,


What is abstraction in oop with example?

0 Answers  


What is coupling in oops?

0 Answers  


What is the difference between class and object?

4 Answers   Apple, Heinz,


Why static Function is used in C++?

4 Answers   TCS,


What is the difference between abstraction and polymorphism?

0 Answers  


Categories