#include <iostream>
struct Mystruct { int a, b; };
//the function return a Mystruct object by value
Mystruct sum_struct(const Mystruct *x, const Mystruct *y)
{
Mystruct ret{0,0};
ret.a = x->a + y->a;
ret.b = x->b + y->b;
std::cout << ret.a << "--" << ret.b << "--\n"; //Shows 6--7--
return ret; //return ret by value
}
int main()
{
Mystruct o, p, q; //note q is not a pointer now
p.a = 1; p.b = 2;
o.a = 5; o.b = 5;
q = sum_struct(&o, &p);
std::cout << q.a << "--" << q.b << "--\n"; // shows 6--7--
}