answersLogoWhite

0

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

12y ago

What else can I help you with?

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.


Difference between struct and union?

A union is a way of providing an alternate way of describing the same memory area. In this way, you could have a struct that contains a union, so that the "static", or similar portion of the data is described first, and the portion that changes is described by the union. The idea of a union could be handled in a different way by having 2 different structs defined, and making a pointer to each kind of struct. The pointer to struct "a" could be assigned to the value of a buffer, and the pointer to struct "b" could be assigned to the same buffer, but now a->somefield and b->someotherfield are both located in the same buffer. That is the idea behind a union. It gives different ways to break down the same buffer area.The difference between structure and union in c are: 1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. 2. In union, one block is used by all the member of the union but in case of structure, each member have their own memory spaceDifference in their Usage:While structure enables us treat a number of different variables stored at different in memory , a union enables us to treat the same space in memory as a number of different variables. That is a Union offers a way for a section of memory to be treated as a variable of one type on one occasion and as a different variable of a different type on another occasion. There is frequent rwquirement while interacting with hardware to access access a byte or group of bytes simultaneously and sometimes each byte individually. Usually union is the answer.=======Difference With example***** Lets say a structure containing an int,char and float is created and a union containing int char float are declared. struct TT{ int a; float b; char c; } Union UU{ int a; float b; char c; }sizeof TT(struct) would be >9 bytes (compiler dependent-if int,float, char are taken as 4,4,1)sizeof UU(Union) would be 4 bytes as supposed from above.If a variable in double exists in union then the size of union and struct would be 8 bytes and cumulative size of all variables in struct.Detailed Example:struct foo {char c;long l;char *p;};union bar{char c;long l;char *p;};A struct foo contains all of the elements c, l, and p. Each element isseparate and distinct.A union bar contains only one of the elements c, l, and p at any giventime. Each element is stored in the same memory location (well, they allstart at the same memory location), and you can only refer to the elementwhich was last stored. (ie: after "barptr->c = 2;" you cannot referenceany of the other elements, such as "barptr->p" without invoking undefinedbehavior.)Try the following program. (Yes, I know it invokes the above-mentioned"undefined behavior", but most likely will give some sort of output onmost computers.)======= Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. In union,one block is used by all the member of the union but in case of structure, each member have their own memory space.Union allocates the memory equal to the maximum memory requried by the member of the union but structure allocates the memory equal to sum of the memory allocated to its each individual members.In Union, one block is used by all the member of union but in case of structure, each member have their own memory space.Union allocates the memory equal to the maximum memory requried by the member of the union but structure allocates the memory equal to total memory requried by the members. In Union, one block is used by all the member of union but in case of structure, each member have their own memory space.

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.


Who is better union j or one direction?

One direction by far!!!!!!!


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.


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.


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 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.


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


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.


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 strategy was better between the union strategy and the confederate?

They were both very good but the only reason that one of them won was because they had more people! They were both very smart plans.


What is one message that sum up the union war?

The message that sums up the Union cause in the War Between the States is "Preserve the Union.