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 Dynamic Polymorphism?
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
#include <iostream> using namespace std; struct wow { int x; }; int main() { wow a; wow *b; a.x = 22; b = &a; a.x = 23; cout << b->x; return 0; }
What are generic functions and generic classes?
what do you mean by static member variable?
Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku
Program to check whether a word is the first word of the sentence.
What is oops and why we use oops?
Can an interface inherit a class?
What is difference between pop and oop?
What is encapsulation with real life example?
What is an example of genetic polymorphism?