From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/SYNTAX/union.html | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 reference/C/SYNTAX/union.html (limited to 'reference/C/SYNTAX/union.html') diff --git a/reference/C/SYNTAX/union.html b/reference/C/SYNTAX/union.html new file mode 100644 index 0000000..5334e3b --- /dev/null +++ b/reference/C/SYNTAX/union.html @@ -0,0 +1,89 @@ +The UNION keyword. + + + + +
+

The UNION keyword.

+
+ +The union keyword allows several +variables of different type and size to occupy the same storage location. +

+The syntax to define a union is simular to the +struct keyword as shown below:

+ + +

+	union union_def { int a; float b; char c;} ;
+
+ +and a variable declared with either of these statements: + +
+	union union_def union_var;
+	union { int a; float b; char c;} union_var;
+
+ +If you wish to initalise a variable you can say: + +
+	union { int a; float b; char c;} union_var=97;
+
+ +By default the first variable (a) is initalised. +

+ +To assign a value to a variable you can say: + +

+	union_var.b=99.99;
+	union_var.a=34;
+	union_var.c='x';
+
+It's important to note that the storage will only hold ONE value, +looking at the +three lines above, union_var.a overwrites union_var.b and +then union_var.c overwrites union_var.a

+ + + +I have yet to see more than one use for this keyword. +


+

Examples:

+ + Here is an example. +
+
+

See also:

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf