What is the difference b/w Structure & Union?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is the purpose of scanf() and printf() functions?
write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.
write a program for even numbers?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
how to write a bubble sort program without using temporary variable?
What is New modifiers?
how to find sum of digits in C?
List some of the dynamic data structures in C?
Give basis knowledge of web designing ...
What is the ANSI C Standard?
can you change name of main()?how?