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 is an operator in c++?

0 Answers  


What do you mean by inheritance in c++? Explain its types.

0 Answers  


What is the difference between set and map in c++?

0 Answers  


write a program that will produce the ff. output. "what fruit will you buy? 1)apple 2)orange 3)mango ENTER CHOICE (1,2 or 3)> HOW MANY WILL YOU BUY?> THAT WILL COST XX.XX

1 Answers  


What will the line of code below print out and why?

0 Answers  






What is a v-table?

0 Answers  


write the code that display the format just like 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 6 5 4 3 2 1

5 Answers  


What is encapsulation in c++?

0 Answers  


Describe functional overloading?

6 Answers   HP,


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

0 Answers  


What is the difference between strcpy() and strncpy()?

0 Answers  


What is the difference between while and do while loop? Explain with examples.

0 Answers  


Categories