answersLogoWhite

0


Best Answer

Sub:- C Programming class:- f.y.b.sc(cs) name:-sintu mehta Union:- all member of the union share is storage in the computer memory 2. Only one member can be active at a time 3. Only first union variable can be initialized 4. Conservation the memoy

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

1. Every individual is accessed in Structure at any time period. Only one person is accessed in Union.

2. All the members of structure can be initialized, where as only the first individual is initialized in Union.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

1. A structure's members have different memory addresses whereas a union's members all have the same memory address.

2. The size of a structure (in bytes) is equal to the sum of the individual member sizes (plus any internal padding required for alignment purposes) whereas the amount of memory allocated to a union is always equal to its largest member.

3. A structure's members can be of the same type but a union's members cannot.

4. A structure can store multiple values simultaneously, but unions can only ever hold one value, regardless of how many members it has.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

A union may have any members, even structures, if that's what you mean.

typedef union myunion {
int i;
float f;
struct sockaddr_in sin;
} myunion;

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Structure is better in fighting, union is better in Chess.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which one is better between structure and union?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Difference between array and union?

All the members of the structure can be accessed at once,where as in an union only one member can be used at a time. Another important difference is in the size allocated to a structure and an union. for eg: struct example { int integer; float floating_numbers; } the size allocated here is sizeof(int)+sizeof(float); where as in an union union example { int integer; float floating_numbers; } size allocated is the size of the highest member. so size is=sizeof(float);


What is anonymous union in c?

union is similar to structure .The distinction is in terms of storage. In structure each member has it own storage location but in union all the members use the same location. It can handle only one member at a time. example. union u { int a; char b[4]; }; A union may contain structure(s) and a structure may contain union(s). A structure (or an union) may contain unnamed unions (and structures), a useful feature and worth getting to know. Example: typedef union MYUNION { . struct { . . int x; . . int y; . } int_coord; . struct { . . double x; . . double y; . } dbl_coord; } MYUNION; It's a fragment of memory shared by multiple variables.


What is data structure why is an array called a data structure which are the other data structures?

A data structure is a collection of more than one elementary item, in some kind of aggregate organization. An array is a type of structure where more than one item of the same type are arranged serially in memory, and accessed using an index. The item can either be an elementary type or it itself can be a structure type. A struct (not to be confused with the use of "structure" in this answer) is a type of structure where more than one item of the same or different types are arranged serially in memory, and accessed using the structure member (.) operator. A union is similar to a struct, except that each member occupies the same address. This means that only one type of data can be stored at any one time in a union. A self-referential structure is a type of structure, usually constructed of simpler structures, linked together with some kind of pointer scheme. Examples of this are the linked list and tree.


What are forest in data structure?

A forest is a disjoint union of trees.


What is the difference between a structure and a machine?

The following differences between a machine and a structure are : 1. The parts of a machine move relative to one another, whereas the members of a structure do not move relative to one another. 2. A machine transforms the available energy into some useful work, whereas in a structure no energy is transformed into useful work. 3. The links of a machine may transmit both power and motion, while the members of a structure transmit forces only

Related questions

How do you Declare and initialized structure list different between union and structure?

C unions are also like structures. We have to allocate more memory when we use stucture.Because, memory needs to be allocated to all structure variables. Where as in Union, less memory is enough to allocate. Because, memory is allocated for only one member which occupies more memory among all members in the union. But, both have their own advantages and disadvantages.I came across one website which gives fair idea of union and structure difference and good sample programs and good explanationsC unionC structure


What is the difference between struct and union in c file management?

The main difference is in how the data structures are stored. In a union, all of the elements are stored in one location. A structure stores each of its elements in a separate memory location.


What is the difference between a structure that is rigid and one that is flexible?

The difference between a structure that is rigid and one that is flexible is that the rigid structure will not bend or flex when force is applied. A structure that is rigid cannot flex.


Who is better union j or one direction?

One direction by far!!!!!!!


Difference between array and union?

All the members of the structure can be accessed at once,where as in an union only one member can be used at a time. Another important difference is in the size allocated to a structure and an union. for eg: struct example { int integer; float floating_numbers; } the size allocated here is sizeof(int)+sizeof(float); where as in an union union example { int integer; float floating_numbers; } size allocated is the size of the highest member. so size is=sizeof(float);


Why was it necessary to form a more perfect union?

Make a better life and be happy when we live all together as one union. there is more than one union in the world.


Why do you go for structure and union?

Structure and union are a form of encapsulating similar data elements.Structure:Whenever a structure is declared, then space equal to the total size of the elements defined inside the structure is allocated. Hence each individual element has its own memory space. Hence structures are commonly used when there is usage for more than one element declared inside the struct at a time.Union:Whenever an union is declared, then space equal to the size of the maximum element defined inside the union is allocated. Hence the individual elements share a common memory space. Hence union is commonly used when there is usage for only one element declared inside the union at a time.


Differentiate structures unions separately?

Structures - A tool for handling a group of logically related data. For example:: struct book { char bookname char authorname int no_of_pages } This is a example of structure coz it is logically related to the object books but at the same time, it has diff data types - char int. UNION:: It is juz a concept borrowed from structures. Diff between structure & union is storage. In structure, each member has its own storage location whereas all the members of a union use the same location. Union can handle only one member at a time, coz only one location is allocated for a union, var irrespective of size


What is a union in c program?

A union, is a collection of variables of different types, just like a structure. However, with unions, you can only store information in one field at any one time


What is the deference between the federal and national union in 1700?

There is a major difference between federal and national unions which was interpreted in the 1700s. A national union is one in which the government that is responsible for operating the entire country makes one sets of laws which all citizens must follow. A federal union is one in which the states take part in the making of laws.


What is anonymous union in c?

union is similar to structure .The distinction is in terms of storage. In structure each member has it own storage location but in union all the members use the same location. It can handle only one member at a time. example. union u { int a; char b[4]; }; A union may contain structure(s) and a structure may contain union(s). A structure (or an union) may contain unnamed unions (and structures), a useful feature and worth getting to know. Example: typedef union MYUNION { . struct { . . int x; . . int y; . } int_coord; . struct { . . double x; . . double y; . } dbl_coord; } MYUNION; It's a fragment of memory shared by multiple variables.


What is the difference between the structure of table salt and table sugar I know one's sweet and one's not but I want to know the difference between the two structures.?

Table salt has a cube structure and table sugar has a hexagonal crystaline structure.