Which uses less memory?
a)
struct astruct
{
int x;
float y;
int v;
};

b)
union aunion
{
int x;
float v;
};

c)
char array[10];

Answers were Sorted based on User's Feedback



Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union au..

Answer / jaroosh

And the explanation for the above answer is :
union has the size of the biggest type of its member, so
here its size is 4, while structs size is 4 + 4 + 4 = 16,
and arrays size is 1 * 10 = 10.

Is This Answer Correct ?    10 Yes 0 No

Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union au..

Answer / guest

Ans is B)

Is This Answer Correct ?    9 Yes 0 No

Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union au..

Answer / gourav bhatt

Mr Ranjeet u r wron vecause ib ur case too the answer will
be "b" .thats gud that u find misktake in jaroosh example but
the anser is b coz the union has size 4 .

Is This Answer Correct ?    0 Yes 0 No

Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union au..

Answer / ranjeet garodia

Jaroosh u r right while calculating the size...
but if u take size of int as 2 then astruct size will be
2+4+2=8
array = 1*10= 10
so c is correct

if size of int is 4, then
struct size will be 4+4+4= 12
then a is correct.

Is This Answer Correct ?    1 Yes 11 No

Post New Answer

More C++ General Interview Questions

Explain one-definition rule (odr).

0 Answers  


Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?

0 Answers  


Why is it necessary to use a reference in the argument to the copy constructor?

0 Answers  


Explain the use of vtable.

0 Answers  


What does n mean in c++?

0 Answers  


Is there a new/delete equivalent of realloc?

1 Answers  


What is the role of static keyword for a class member variable?

0 Answers  


what is upcasting in C++?

0 Answers  


can anybody please tell me how to write a program in c++,without using semicolon(;)

6 Answers   NIIT,


In which memory a class gets stored(in heap /in stack)? And why??

2 Answers  


In the derived class, which data member of the base class are visible?

0 Answers  


Define a constructor?

0 Answers  


Categories