answersLogoWhite

0


Best Answer
Answer

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


AnswerThis is the same problem as getting the previous value of a regular variable. For example:
int x = 5;
x = 2;

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

User Avatar

Wiki User

2009-10-13 07:59:39
This answer is:
User Avatar
Study guides

What is a programming language

What does DOS stand for

What is a software that is distributed for free

What do unix and Linux have in common

➡️
See all cards
3.95
61 Reviews

Add your answer:

Earn +20 pts
Q: If the variables in a union use the same address so the previous value will be lost if a new value is entered how do you get the previous value?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


What is the difference between a class and a union in c plus plus?

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.


What are advantages and disadvantages of union in c language?

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


How can the union member share 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.


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

Related questions

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.


What was the date when Louisiana entered the union?

Lousiana entered the union on 1812


What states entered the union?

All of the fifty (50) states have entered the union.


Can Minnesota entered the union as a state?

Yes. It entered the Union as a state in 1858.


What day was Georgia entered into the union?

January 2, 1788 Georgia entered the Union.


When Missouri entered the Union as a free state California entered the Union as a free state?

Under the provisions of the Missouri Compromise, Maine was the state that entered the Union with Missouri.


Which was the first state entered the union?

Which state entered the union in 1916 as an officially bilingual state?


Why the colony of Massachusetts entered the union?

The entered union of Massachusetts is Feb. 6, 1788(6th)


What state entered the Union as a free state as a result of the Missouri Compromise?

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.


Which state entered the union in 1916 as an officially bilingual state?

None of the US states entered the Union in 1916. New Mexico entered the Union as an officially bilingual state in 1912.


What states entered the union between 1851 and 1876?

Which states entered the Union between 1851 and 1876


What states entered the union in 1959?

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.

People also asked