// defines point, rectangle
// illustrates structures, access, etc

struct point {
	int x;
	int y;
};

struct rectangle {
	struct point p1;  // lower left corner
	struct point p2;  // upper right corner
};

int compute_area( struct rectangle );
struct point add_points( struct point , struct point );
struct point add_points_ptr( struct point *, struct point * );

int main()
{
	struct point p1;
	struct point p2;
	struct point p3;
	struct rectangle r;
	
	p1.x = 0;
	p1.y = 0;

	p2.x = 10;
	p2.y = 37;

	// structure assignment (copy by value)
	// namespace issue?? no
	r.p1 = p1;
	r.p2 = p2;

	p3 = add_point( p1 , p2 );
	
	return 1;
}

int compute_area( struct rectangle r )
{
	int width = r.p2.x - r.p1.x;
	int height = r.p2.y - r.p2.y;
	
	return width * height;
}
=

/* pass by value --> p1 is a copy of argument, so no mutation */
struct point add_points( struct point p1 , struct point p2 )
{
	p1.x += p2.x;
	p1.y += p2.y;
	return p1;
}

/* pass by pointer (illustrates pointer to member) */
struct point add_points_ptr( struct point *p1 , struct point *p2 )
{
	struct point p_new;
	p_new.x = p1->x + p2->x;
	p_new.y = (*p1).y + (*p2).y;
	
	return p_new;
}