Purpose: a single variable that can legitimately hold any of one of several types.
Eg:
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.
This blog is all about technical questions in C, C++, data structures like linked lists, Binary trees, UNIX and other software developement issues which I faced.
Saturday, September 13, 2008
Difference between Structure and Union.
As most of the people know the answer.Yes ur right , the size of the structure is total size of the variables where as for Union ,size is max size of the variables.
struct size
{
int i;
float f;
char c;
};
and size of this structure is 9 bytes (4(int)+4(float)+1(char) ) depending on the machine.
You may get 12bytes on some machines because of structure Padding ,i will write abt this in the next post.
union size
{
int i;
float f;
char c;
};
and the size of this union is max size of the variable i.e 4 bytes(int or flaot 4 byets).
struct size
{
int i;
float f;
char c;
};
and size of this structure is 9 bytes (4(int)+4(float)+1(char) ) depending on the machine.
You may get 12bytes on some machines because of structure Padding ,i will write abt this in the next post.
union size
{
int i;
float f;
char c;
};
and the size of this union is max size of the variable i.e 4 bytes(int or flaot 4 byets).
Monday, September 8, 2008
My First post.
Hi All,
This is Chandra Sekhar working as a software developer. And the reason for creating this blog is to share the problems I faced at my work .
This is Chandra Sekhar working as a software developer. And the reason for creating this blog is to share the problems I faced at my work .
Subscribe to:
Posts (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...