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

What is design patterns in C++?

2 Answers   Persistent,


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

0 Answers  


Why do while loop is used?

0 Answers  


What polymorphism means?

0 Answers  


What are the four main oops concepts?

1 Answers  






what is the difference between class and object?

9 Answers  


Why do we use virtual functions?

4 Answers  


the difference between new and malloc

5 Answers   Siemens,


what is virtual destructor

7 Answers   L&T, TCS,


How to improve object oriented design skills?

0 Answers  


why overriding?

3 Answers  


In which cases you use override and new base?

2 Answers  


Categories