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
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 |
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 |
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 |
Which programming language should I learn first?
Why c++ is better than c language?
Explain the use of virtual destructor?
What is the difference between while and do while loop?
What are put and get pointers?
Why is c++ called oops?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create
Does there exist any other function which can be used to convert an integer or a float to a string?
Write a function which takes a character array as input and reverses it in place.
2 Answers Lehman Brothers, Vision Infotech,
When does the c++ compiler create temporary variables?
What do you mean by function pointer?
What are proxy objects?