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 are the five basic elements of a c++ program?

580


Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.

2436


What is a container class? What are the types of container classes in c++?

676


How do I write a c++ program?

593


Explain about vectors in c ++?

591






Is recursion allowed in inline functions?

605


How a modifier is similar to mutator?

630


What is the standard template library (stl)?

621


What are the operators in c++?

592


Why is swift so fast?

618


What is the keyword auto for?

569


What are activex and ole?

538


What is function overloading in C++?

723


what are the iterator and generic algorithms.

1459


Explain some examples of operator overloading?

643