Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

Write an operator overloading program to write S3+=S2.

2 Answers  


tell about copy constructor

3 Answers   Siemens,


#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

0 Answers  


What does and I oop mean?

0 Answers  


What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.

2 Answers  






How do you use inheritance in unity?

0 Answers  


What is the use of fflush(stdin) in c++?

4 Answers   HCL,


Write a program to sort the number with different sorts in one program ??

0 Answers   NIIT,


What is class and object in oops?

0 Answers  


Write a macro for swapping integers

5 Answers  


What are the different forms of polymorphism??

8 Answers   Mantaq, NUC, PCS,


write a C++ program for booking using constructor and destructor.

0 Answers   HAL,






Categories