A structure in C is analogous to a record in Delphi. A record can be thought of as a kind of complex variable declaration.type
MyData = record
phonenum : string;
married : boolean;
age : integer;
name : string;
end;
var
Datalist : MyData;
In this example we use the type statement to create a custom data type, in this case a record. The declaration of the record can then be used in the var statement to initalize an actual instance of the declared data type. The record above is a kind of a custom variable which consists of a number of different variable types stored as a single data record.We can access a field of the record using the dot operator.
thephonenum := Datalist.phonenum;
Sometimes it is more convenient to use pointers to records.
type MyDataListPointer = ^MyData;
The declaration of the MyData record then follows as above and then in the var declaration we declare a pointer to a record instead of a static instance of a record.
var
DataListPtr : MyDataListPointer;
We then create an actual record from this pointer using the new statement.new(DataListPtr);
And we access the fields of the record using pointer syntax.
DataListPtr^.phonenum := '336-3344';
There are many variations in the way records (or structures) are stored and manipulated (linked lists, arrays of records, etc.) It is impossible to access common graphics formats, Windows or Linux API functions, etc., without dealing with records and so this is a very common and very important data type. Records, or structures as they are called in C, are used throughout APIs and as interfaces to many standard functions. (For example a common bitmap graphic consists of a structure (or record in Delphi), which is referred to as the Bitmap info header, which stores in record form all the information about the height, width, color depth, etc., of the following raw bitmap data in the file.) The usefulness of records (or structures as C calls them) in database applications should be obvious, and they are used in any application where related data must be stored conveniently in a single structure.
If you are familiar with records in Delphi, the structure in C encapsulates the same idea using the syntax defined for this purpose in the C language. The keyword 'record' and the syntax illustrated above is used to define records in Delphi, and C uses the keyword struct and the following syntax...
struct MyData {
char phonenum[8];
bool married;
int age;
char name[20];
};
This struct statement creates the equivalent of the record declared in Delphi above. This declaration defines the 'type' of the structure, just as using the type declaration in Delphi to declare a variable of the type record. To create an instance of the record in Delphi you use it in the var declaration as the variable type for the variable being declared as demonstrated above. In C you can crate an instance of the structure by including the name of the variable after the closing curly braces and before the final semi-colon which completes the definition.struct MyData {
char phonenum[8];
bool married;
int age;
char name[20];
}Datalist;In the example above we have described the type of the structure and then we created an instance of the structure - a variable given the name Datalist. Note that C is case sensitive, so a variable named Datalist is not the same as a variable named datalist or DataList, whereas all three would refer to the same variable in Delphi, which is not case sensitive.
Alternatively, an instance of the structure can be declared at any place in code prior to using the structure, just as any other variable is declared in C. Unlike in Delphi, the variable type precedes the name of the instance of the variable.
MyData DataList;
This declares a variable DataList which is the type MyData, which means that the program allocates memory for the structure defined above, creating an instance of this record.The fields of the record can then be accessed using the dot operator, as in Delphi, and using standard C functions.
To copy a string into a field within the structure...
strcpy(Datalist.phonenum, "383-4455");
or to fill in other fields...
Datalist.age = 51;
Datalist.married = true;
And so on...
Instances tructures can be declared as arrays of records, for example as part of a database application. Here we will declare an array of 20 records...
MyData Datalist[20];
Each individual record can then be accessed using array syntax combined with the dot operator used to access record fields...
Datalist[0].age = 51;
And so on...
Structures can also be filled in using the following syntax. Let's assume that the a record exists with a string field, and a couple of integer fields, and the structure name is Datalist.
Datalist = { "Some Name", 12, 102};
Arrays can also be filled in the same way. The following C++ example creates an array of 3 strings.
string sarray[3];
sarray[0] = 'Hello';
sarray[1] = 'there';
sarray[2] = 'world';This could also be accomplished using the following code...
string sarray = {'Hello', 'there', 'world'};
Initializer lists (like the above) can be used when the array is declared and in this case the dimension of the array can be omitted (the compiler can make the determination based on the initializer list).
Arrays can also be dynamically created, and the dimension can be passed as an integer variable, making the declaration truly dynamic. Here we assume that x is an integer variable that has been previously initialized to the required number of strings in the array. Notice that declaration is different in that the use of the pointer symbol (the asterik) indicates that this is going to be a dynamic array...
string* sarray = new string[x];
sarray[1] = 'Hello';
sarray[2] = 'there';
sarray[3] = 'world';
Here the programmer is going to have to code to make sure that bounds of the array are not violated, since the compiler will not know if '3' is out of range since the array was declared dynamically using a variable (x in the example above).In C++ the name of an array is actually a pointer to the first element in an array. When arrays are passed to functions as parameters you might see either of the two following ways of describing the array...
int somefunction(int anarray[], int size);
int somefunction(int* anarray, int size);
Both the above declarations describe an array parameter passed to a function, with the pointer pointing to the first element in the array.
Within the body of the function the elements of the array are then accessed using the usual syntax...
anarray[2] = 12;
Multidimensional arrays are declared as follows...int anarray[4][6][7]; ... a 3-d array...
Initializer lists can be used when the array is declared...
int anarray[2][2] = { {2, 4}, {5, 6} };
C++, like Delphi, allows types to be declared and then the type to be used to declare instances of variables. In the example above the delphi 'type' keyword was used to declare records consisting of variables. This record type was then used to create an actual instance of the record type.
In C++ the keyword used is 'typedef' (the definition of a type which can then be used to create instances of variables...) In both Delphi and C++ arrays can also be declared as types and then the type used to create actual arrays (typically this is done in the case of multidimensional arrays). The type definition is included at the top of the unit...
#include <whatever.h>
...etc etc ...
const int X = 12;
const int Y = 14;
typedef int TwoDArray[X][Y];
..etc etc ...
int somefunction(TwoDArray, int, double);
In the body of the code the type (TwoDArray) is then used to create instances of the variable in the usual way...TwoDArray anarray;
An initializer list can also be used to put values into the array as it is delcared as illustrated above, although it is also typical to use loops (for loops in particular) to initialize or otherwise manipulate arrays...
The fields of a multidimensional array are accessed as follows...
anarray[2][8] = 32;
A Unified Field Theory
![]()
The Unified Field Theory
is also available as a zip file -> unified.zip
Introduction :The Pioneer Effect and the New Physics. A brief description of the new physics required to explain the 'Pioneer Effect', which is the constant deceleration of space craft as they fly through space.

