412 Programming and Data Structures
without separating the offset and segment address, address is assigned to register DX. It works correctly
in small memory model because there is only one data segment in small memory model and DS
register always contains the segment address. If you try this program with other memory models it
won't run successfully. To make this program suitable for all the memory models we need to make the
address of file far. This address is then separated into offset and segment parts. For that C provides
two macros FP_SEG and FP_OFF. The description of far pointer and FP_SEG and FP_OFF macros is
beyond the scope of this book.
12.13 UNION OF STRUCTURES
We know that one structure can be nested within another structure. It the same way a union can be
nested within another union. We can also create structure in a union or vice versa.
12*36 Write a program to use structure within union. Display the contents of structure
elements.
# include <stdio.h>
# include <conio.h>
void main ()
{
struct x
{
float f>
char p [2 ];
}>
union z
{
struct x set;
union s st;
*t.set.fa5.5;
pt.set.p[0]«65;
s t.s e t.p [l]- 66/
clrsc rO ;
printf ( n %g",st.set.f);
printf (" n % c"rst.set.p[01);
printf (" n % c",st.set.p[l]);
I
OUTPUT;
Explanation In the above program structure x is defined. The union z contains structure member as
its member variable. The variable s t is an object of union z . The member variables of structure x are
assigned with certain values. Using objects of structure and union with dot operator member contents
of member variables are displayed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96