#include struct myStruct // How to define a "struct" type { // This is NOT a variable definition int i; // It serves to tell C++ what "myStruct" looks like float f; }; struct myStruct x; // How to define struct variables int main(int argc, char *argv[]) { struct myStruct A[3]; // How to define arrays of struct variables struct myStruct y // How to define initialized struct variables = {1, 2.1}; extern struct myStruct x; // How to DECLARE struct variables; void Print1(struct myStruct); // How to pass struct by VALUE void Print2(struct myStruct &); // How to pass struct by REFERENCE Print1(y); x.i = 1234; // How to use a struct variable x.f = 3.14; Print1(x); Print1(x); A[1].i = 333; // How to use an array of struct variable A[1].f = 2.17; Print1(A[1]); Print2(x); Print2(x); } /* ---------------------------------------------- How to pass structure by VALUE ---------------------------------------------- */ void Print1(struct myStruct h) { cout << "Structure values = (" << h.i << ", " << h.f << ")\n"; h.i = h.i + 1000; h.f = h.f + 1000; } /* ---------------------------------------------- How to pass structure by REFERENCE ---------------------------------------------- */ void Print2(struct myStruct & h) { cout << "Structure values = (" << h.i << ", " << h.f << ")\n"; h.i = h.i + 1000; h.f = h.f + 1000; }