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

What are member functions used in c++?

0 Answers  


Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.

0 Answers  


What issue do auto_ptr objects address?

2 Answers  


What is the most powerful coding language?

0 Answers  


What do you mean by a template?

0 Answers  


What is the best sorting algorithm, when there is a large amount of data, that cannot be fit in the main memory. ?

1 Answers   Yahoo,


What and all can a compiler provides by default?

3 Answers   Accenture, HP,


When can I use a forward declaration?

0 Answers  


What is the difference between mutex and binary semaphore?

0 Answers  


Give an example of run-time polymorphism/virtual functions.

0 Answers  


Difference between static global and global?

16 Answers   Microsoft, Symphony, Wipro,


What is object in c++ example?

0 Answers  


Categories