Adding to what he said, if you want to pass it to a function like regular but also save memory, pass it as a const reference.Originally posted by poccil
It's usually more efficient to pass a structure by reference, as it saves space on the system stack:
Code:#include <iostream.h> typedef struct{ int mymember; } MYSTRUCT; int SomeFunction(MYSTRUCT &mys){ // passing by reference mys.mymember=5; return 0; } int main(){ MYSTRUCT struc; struc.mymember=2; cout << "mymember=" << struc.mymember << endl; // "mymember=2" SomeFunction(struc); cout << "mymember=" << struc.mymember << endl; // "mymember=5" return 0; }
That will work like normal and save space.Code:struct random{ int i; int j; }; int function(const random &num);