The union keyword is used for declaring unions. A union is a collection of one or more variables (union_members) that have been grouped under a single name. In addition, each of these union members occupies the same area of memory

Files Recovery Software
Home Contact Details Customer Support Download Demo Products  

 
 

The union Keyword

union tag {
union_member(s);
/* additional statements may go here */
}instance;

The union keyword is used for declaring unions. A union is a collection of one or more variables (union_members) that have been grouped under a single name. In addition, each of these union members occupies the same area of memory.

The keyword union identifies the beginning of a union definition. It's followed by a tag that is the name given to the union. Following the tag are the union members enclosed in braces.

An instance, the actual declaration of a union, also can be defined. If you define the structure without the instance, it's just a template that can be used later in a program to declare structures. The following is a template's format:

union tag {
union_member(s);
/* additional statements may go here */
};

To use the template, you would use the following format:
union tag instance;

To use this format, you must have previously declared a union with the given tag.

/* Declare a union template called tag */
union tag {
int num;
char alps;
}
/* Use the union template */
union tag mixed_variable;

/* Declare a union and instance together */

union generic_type_tag {

char c;
int i;
float f;
double d;

} generic;

/* Initialize a union. */
union date_tag {

char full_date[9];

struct part_date_tag {

char month[2];
char break_value1;
char day[2];
char break_value2;
char year[2];

} part_date;

}date = {"09/12/80"};

Let us better understand it with the help of examples:

#include <stdio.h>

int main()
{
union
{
int value; /* This is the first part of the union */

struct
{
char first; /* These two values are the second part of it */
char second;
} half;

} number;

long index;

for (index = 12 ; index < 300000L ; index += 35231L)
{
number.value = index;
printf("%8x %6x %6x\n", number.value,
number.half.first,
number.half.second);
}

return 0;
}

And the output of the program will be displayed as follows:

 

       c      c      0
89ab   ffab   ff89
134a     4a     13
9ce9   ffe9   ff9c
2688   ff88     26
b027     27   ffb0
39c6   ffc6     39
c365     65   ffc3
4d04      4     4d

 

Previous page

page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20

 
 

page 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37

 
 

page 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54

 
 

page 55 | 56 | 57 | 58 | 59 | 60

Next page
 
 
Data Recovery Book
 
Chapter 1 An Overview of Data Recovery
Chapter 2 Introduction of Hard Disks
Chapter 3 Logical Approach to Disks and OS
Chapter 4 Number Systems
Chapter 5 Introduction of C Programming
Chapter 6 Introduction to Computer Basics
Chapter 7 Necessary DOS Commands
Chapter 8 Disk-BIOS Functions and Interrupts Handling With C
Chapter 9 Handling Large Hard Disks
Chapter 10 Data Recovery From Corrupted Floppy
Chapter 11 Making Backups
Chapter 12 Reading and Modifying MBR with Programming
Chapter 13 Reading and Modifying DBR with Programming
Chapter 14 Programming for “Raw File” Recovery
Chapter 15 Programming for Data Wipers
Chapter 16 Developing more Utilities for Disks
Appendix Glossary of Data Recovery Terms
 
 
Pro Data Doctor

Home

Products

Contact Details

Customer Support

Download Demo

Terms and Conditions

 
Pro Data Doctor