Structure is a query that is used in language c++
all the three are user defined datatypes
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
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.
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
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
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.
The answer depends on whether you mean A intersecting (B union C) or (A intersecting B) union C.
Formula is C3O2, structure is:O=C=C=C=O
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.
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.
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.