#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[]) { void f1(struct myStruct); // pass struct by VALUE void f2(struct myStruct &); // pass struct by REFERENCE x.i = 1234; // How to use a struct variable x.f = 3.14; cout << "initially: x = " << x.i << " " << x.f << endl << endl; f1(x); cout << "after f1(x): x = " << x.i << " " << x.f << endl << endl; f2(x); cout << "after f2(x): x = " << x.i << " " << x.f << endl << endl; } /* ---------------------------------------------- How to pass structure by VALUE ---------------------------------------------- */ void f1(struct myStruct h) { h.i = h.i + 1000; h.f = h.f + 1000; } /* ---------------------------------------------- How to pass structure by REFERENCE ---------------------------------------------- */ void f2(struct myStruct & h) { h.i = h.i + 1000; h.f = h.f + 1000; }