answersLogoWhite

0

Structure and union in c

Updated: 8/16/2019
User Avatar

Wiki User

13y ago

Best Answer

Both usable.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Structure and union in c
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is structure and union?

Structure is a query that is used in language c++


What is similarity among structure union and enum in c language?

all the three are user defined datatypes


Difference between structures and union in c Language?

Structure: Structure is a combination elements, which can be predefined data types or other structure. The length/size of the structure is the sum of the length of its elements.In C, structures cannot containn functions. in C++ it can.Union: Union is a combination elements, which can be predefined data types or other union . But, the size/length of union is the maximum of internal elements.the sizeof() operator returns the size slightly more than calculated size due to padding, which again depends on OS


The fields in a c program are by default private is true or not?

I guess you mean C++, not C.Data fields of a structure/union are public by default,those of a class are private by default.


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


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


How do you solve A intersecting B union C?

The answer depends on whether you mean A intersecting (B union C) or (A intersecting B) union C.


What is the structure of carbon sub-oxide?

Formula is C3O2, structure is:O=C=C=C=O


What are the advantages of using Unions in a structure in C?

In case of structure each variables have their own storage location whereas for unions all the variables share a common memory location. In structure all the variables can be handled at a time but for union only a member can be handled at a time.


Is it true that if a union c equals b union c then a equals b?

No- this is not true in general. Counterexample: Let a = {1,2}, b = {1} and c ={2}. a union c = [1,2} and b union c = {1,2} but a does not equal b. The statement be made true by putting additional restrictions on the sets.


What is class union in c language?

A union is often confused with the structure data-type that can contain multiple data items simultaneously. A union can contain only one piece of data and that data may be of any data type.struct foo{int a;long b;float c;char d[80];}my_struct;The structure foo will have space for all the variables.union bar{int a;long b;float c;char d[80];}my_union;The union bar will have 80 bytes assigned to it, 80 being the size of the largest variable (char d[80]). At any given time only one variable can be stored in bar.my_union.a is used to read or write an int.my_union.b is used to read or write a long.my_union.c is used to read or write a float.my_union.d is used to read or write a string.C does not have classes, C++ has class unions (a union used to define a class). A class union is the same as a union in C but gets its name from how it is used.