///////////////////////////////////////////////////// // struct.cpp - how do I define and use a struct? // ///////////////////////////////////////////////////// #include using namespace std; void main() { struct test { // struct declaration int x; // defines a pattern of memory use double d[3]; char *pChar; }; test one; // struct definition allocates memory one.x = 3; // this is how struct memory is initialized one.d[0] = 0.5; one.d[1] = 1.5; one.d[2] = 2.5; one.pChar = new char[3]; one.pChar[0] = 'a'; one.pChar[1] = 'b'; one.pChar[2] = 'c'; cout << "\n one = {" // this is how struct memory is used << "\n " << one.x << "\n " << one.d[0] << ", " << one.d[1] << ", " << one.d[2] << "\n " << one.pChar[0] << ", " << one.pChar[1] << ", " << one.pChar[2] << "\n }\n\n"; }