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

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

c)
char array[10];

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c++ coding?

759


What is size_type?

634


Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

696


Define token in c++.

810


Why is c++ difficult?

688






Write a code/algo to find the frequency of each element in an array?

703


Write a program to interchange 2 variables without using the third one.

675


What are the benefits of c++?

674


What is guard code in c++?

741


What is the difference between object-oriented programming and procedural programming?

790


What are register variables?

730


What is stl containers in c++?

673


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

708


Which coding certification is best?

647


What are put and get pointers?

697