What is the difference b/w Structure & Union?

Answers were Sorted based on User's Feedback



What is the difference b/w Structure & Union?..

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

What is the difference b/w Structure & Union?..

Answer / karthikkumareg

in structure struct key word is used but in union union key
word is used.

Is This Answer Correct ?    6 Yes 9 No

What is the difference b/w Structure & Union?..

Answer / raj kumar

struct can hold multiple data types.
Like u can define a date structure....
but union can multiple data types which includes struct also

union x
{
int x;
struct
{
...
...
}
}

Is This Answer Correct ?    2 Yes 7 No

Post New Answer

More C Interview Questions

Explain pointer. What are function pointers in C?

0 Answers   HCL,


hi , please send me NIC written test papers to sbabavalli@gmail.com

0 Answers   NIC,


How can I do peek and poke in c?

0 Answers  


What is non linear data structure in c?

0 Answers  


What is the difference between CV and Resume ?

2 Answers  






What is the difference between c and python?

0 Answers  


How does sizeof know array size?

0 Answers  


main() { enum _tag{ left=10, right, front=100, back}; printf("%d, %d, %d, %d", left, right, front, back); }

1 Answers   Accenture, Vector,


hello everybody can we change a the adress of a variabl i mean can i put for exemple for a int *p: &p=6 ?????????

1 Answers  


Why we use break in c?

0 Answers  


Write a program to swap two numbers without using third variable?

0 Answers  


write a Program to dispaly upto 100 prime numbers(without using Arrays,Pointer)

26 Answers   ADITI, iFlex, Infosys, Oracle, TCS, Unicops, Wipro,


Categories