What is the difference b/w Structure & Union?

Answer Posted / nakul sharma

Memory allocated for any structure is equal to the sum of
memory required by each structure member.

Example: In a structure 'abc' below, memory allocated will
be 7 Bytes (2 Bytes for int a + 1 Byte for char b + 4 Bytes
for float c ina 32 bit processor)
struct abc
{
int a;
char b;
float c;
}

But in union memory allocated for it is equal to the memory
required by the biggest (in terms of memory it use) union
member.

Example: In a union 'abc' below, memory allocated will be 4
Bytes as float c is the biggest union member here and it
uses 4 Bytes of memory in 32 bit processor.

union abc
{
int a;
char b;
float c;
}

Is This Answer Correct ?    19 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

627


What is time complexity c?

558


Why do we use & in c?

580


Why do we use null pointer?

599


List some applications of c programming language?

539






Explain threaded binary trees?

670


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1576


What is a pointer on a pointer in c programming language?

611


"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

603


What are extern variables in c?

539


What is identifier in c?

535


What is static memory allocation?

597


What should malloc(0) do?

608


Is c still relevant?

631


Explain setjmp()?

649