Saturday, September 13, 2008

More on Unions.

Purpose: a single variable that can legitimately hold any of one of several types.

Suppose a constant may be an int, a float, or a character pointer. The value of a particular constant must be stored in a variable of the proper type, yet it is most convenient for table management if the value occupies the same amount of storage and is stored in the same placeregardless of its type.

union u_tag {
int ival;
float fval;
char *sval;
} u;
The variable u will be large enough to hold the largest of the three types.

i.e any one of the three variables (not all) value will be hold.

No comments:

Popular Posts