Structs are a a type from C that C++ used as a template for classes. We will briefly look at structs since they define data (i.e., data members) the same way as classes do. However, classes also permit us to define methods (i.e, functions).
struct EMPLOYEE { int emp_no; char name[20]; char address[40]; };
struct EMPLOYEE engineer;
EMPLOYEE engineer;
= {143, "George", "123 Main St."};
rec array[30]; array[5].i = 8;
struct rec array[3][4][2]; array[2][3][1].i = 9; /*The last element of the array */
fn1(engineer.emp_no); // call fn1 (int emp_no) //header
fn2 (engineer); //call fn2 (struct employee E) //header
Emp = fn3( ); // call struct employee fn3 ( ) //header struct employee var; // decl return (var) //return
struct rec { int i; float f; char c; }; rec *rec_ptr; rec_ptr = new struct rec; (*rec_ptr).i = 30; /* or rec_ptr->i = 30 */ rec_ptr->f = 1.234; rec_ptr->c = 'X'; delete(rec_ptr);
union Number { int i; float f; };
union Number value = { 8}; /* 3.4 would be invalid */
value.i = 100; cout << value.i; value.f = 123.45; cout << value.f;
enum colors = { red, blue, green };
enum colors rainbow; OR COLORS rainbow;