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

A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

0 Answers  


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

0 Answers  


what do u mean by Direct access files? then can u explain about Direct Access Files?

0 Answers   LG Soft,


what are bitwise shift operators?

4 Answers  


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

0 Answers  






How many bytes is a struct in c?

0 Answers  


What is the significance of scope resolution operator?

0 Answers   Agilent, ZS Associates,


How can variables be characterized?

0 Answers  


Why is this loop always executing once?

0 Answers  


Explain modulus operator. What are the restrictions of a modulus operator?

0 Answers  


2)#include<iostream.h> main() { printf("Hello World"); } the program prints Hello World without changing main() the o/p should be intialisation Hello World Desruct the changes should be a)iostream operator<<(iostream os, char*s) os<<'intialisation'<<(Hello World)<<Destruct b) c) d)none of the above

4 Answers   Siemens,


main() { int i; printf("%d",i^i); }

1 Answers  


Categories