Wiki User
∙ 2009-10-13 07:59:39quite a low level view required ......everything stored in memmory is in form of bits (i.e. a sequence of 01). It dependes upon how you are going to read a value. Same sequence of bits can give you different values..try printing x=10; printf("%c %d",x,x);
How do you get the previous value of x (5)? If you didn't store the value in another variable before overwriting it with 2, then you can't. The old value is overwritten and cannot be recovered. In a union, it's possible that you might overwrite only part of a previous value if you store a value to a smaller data type. For example:
union { long a; short b; } c;
c.a = 5;
c.b = 2;
It's possible that you can recover some of the old data of c.a, but for most practical purposes that value would be garbage (and it really depends on the exact alignment of the variables and byte endianness).
Wiki User
∙ 2009-10-13 07:59:39A union is an aggregate of members that share the same memory address. The size of a union is determined by the largest member.
The data members of a class are each allocated separate memory addresses. A union's members are all mapped to the same address. If you change the value of one union member, you change them all.
The basic advantage is that union will use the memory space of the datatype which has the highest memory.... hence memory consumption will be less... But when u use structure the total memory will be the sum of the memory of all datatypes.. ie.(higher memory allocation) Disadvantage is that..... when you use the union.... only the last entered variable can be directly accessed as only the last added data to the union will exist in the memory...
All union members are allocated the same memory address. The amount of memory allocated is determined by the largest member of the union. Only one value can be stored in a union. If we change the value of any one member, we change the value for all members. The member type determines how the current value is interpreted.
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.
A union is an aggregate of members that share the same memory address. The size of a union is determined by the largest member.
Lousiana entered the union on 1812
All of the fifty (50) states have entered the union.
Yes. It entered the Union as a state in 1858.
January 2, 1788 Georgia entered the Union.
Under the provisions of the Missouri Compromise, Maine was the state that entered the Union with Missouri.
Which state entered the union in 1916 as an officially bilingual state?
The entered union of Massachusetts is Feb. 6, 1788(6th)
the state that entered the Union as a free state was Maine and the state that entered the Union as a slave state was Missouri.
None of the US states entered the Union in 1916. New Mexico entered the Union as an officially bilingual state in 1912.
Which states entered the Union between 1851 and 1876
There were two states that entered into the Union in the year 1959. These states were Alaska and Hawaii and the last to enter the Union.