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 :( :-?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is encapsulation with example?

577


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

628


Is enum a class?

602


design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

6144


What is balance factor?

582






Advantage and disadvantage of routing in telecom sector

784


What is a class in oop?

599


How do you define a class in oop?

626


Why do we use class in oops?

553


What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?

1650


how to get the oracle certification? send me the answer

1668


What is a class oop?

592


What is an example of genetic polymorphism?

647


Can main method override?

583


What are two types of polymorphism?

607