answersLogoWhite

0

it is not necessary to have same size for all members in an union ..because unions holds different data types..

What else can I help you with?

Related Questions

IS it necessary to have same size for all members in an union Explain?

it is not necessary to have same size for all members in an union ..because unions holds different data types..


How memory space is occupied by union variables in C programming language?

A union is an aggregate of members that share the same memory address. The size of a union is determined by the largest member.


How does union works in c?

Union is a heterogeneous (having different data types) data structure. In union,all members share same memory for their storage..keyword used is union.it is similar to structures only keyword is different. size assigned to union is the size of the largest data type in the union. for example consider a union abc- union abc{ int int1; char ch1; double db; }un; the size of un will be 8 byte, since it is the size of the largest data type in the union. we can assign a value to only one component of the union at a time, it will overwrite the last value.


How union works in c?

Union is a heterogeneous (having different data types) data structure. In union,all members share same memory for their storage..keyword used is union.it is similar to structures only keyword is different. size assigned to union is the size of the largest data type in the union. for example consider a union abc- union abc{ int int1; char ch1; double db; }un; the size of un will be 8 byte, since it is the size of the largest data type in the union. we can assign a value to only one component of the union at a time, it will overwrite the last value.


Is a struct or a union more preferable in C programming?

They both do entirely different things so the preferred option is the one that fulfils your needs. A struct is used to combine two or more data types (members) into a single entity, where each member is stored and accessed separately within a contiguous block of memory. The size of a struct is equal to the total size of all its members, plus any padding for alignment purposes. A struct is not unlike a database record with two or more fields. However, to conserve memory and minimise padding, members must be declared in order of size, from largest to smallest. A union is used to store a single data type that can be re-interpreted, not unlike a static cast. The largest member determines the overall size of the union and the individual members determine how the memory is to be interpreted. Since all members effectively refer to the same memory address, only one member of a union may be accessed at any one time. Changing the value of any one member affects all members. Structs and unions can be combined both ways, so a struct may contain a union (allowing the same struct member to be re-interpreted) and a union may contain a struct. The latter form makes it possible for a union to contain a primitive data type, such as a 32-bit integer, as well as a struct member that contains two or more members that have a combined size of 32-bits, such as four separate 8-bit members (bytes). Changing the value of any one byte in the struct affects a different byte within the 32-bit integer because both the integer and the struct are mapped to the same address space.


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);


Difference between enum and const in c?

members in union and enum both shares memory and the size of the union is the size of the highest element like if there is one int and one char in union then the size of union will be the size of an int. if an int and an float are there then the size of the union will be the size of the float. This is not the case in the enum. it has similar type of members. and the value of the members can be assign manually like this enum e{ZERO,ONE,TWO=20,THREE}; here ZERO will have value 0, ONE will have value 1, TWO will be having 20 , THREE will be having 21.. and so on Answer: they are no way similar, no point in comparing them.


Which is bigger the us or the European union?

The European Union is an organisation, not a place, so it does not have a size to compare with. It does have countries as members and if you take the combined area of those countries then the US would be bigger.


Which one is better between structure and union?

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


How do you compare and contrast congruent and similar?

Similar means they are of the same shape but not necessary the same size. two figure are congruents when they are of the same shape and size. congruent figures can be similar but not similar figures aren't always congruent


When alaska and hawaii became states who was presidents?

Dwight David Eisenhower, 34th presidentBecause their size, population and importance to the Nation merited representation as full members of the Union.


Do the intersection of two sets always contains a smaller number of terms than the union of two sets?

No, because the intersection of two equivalent sets will have a union the same size as its intersection.