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
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 |
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 |
what is object slicing
What is encapsulation?
how to swap to variables without using thrid variable in java?
Why static functions always uses static variables?
What is the real time example of inheritance?
why function overloading is not called as pure polymorphism?
What are the 5 oop principles?
what is ns string? what is ns array?
There are 2 classes defined as below public class A { class B b; } public class B { class A a; } compiler gives error. How to fix it?
What are the fields of vtable
What does the code "cout<<(0==0);" print? 1) 0 2) 1 3) Compiler error: Lvalue required
what is SPL in c++.