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
What is encapsulation with example?
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.
Is enum a class?
design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)
What is balance factor?
Advantage and disadvantage of routing in telecom sector
What is a class in oop?
How do you define a class in oop?
Why do we use class in oops?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
how to get the oracle certification? send me the answer
What is a class oop?
What is an example of genetic polymorphism?
Can main method override?
What are two types of polymorphism?