结构体定义的问题
#include<math.h>#include<stdio.h>
//定义点结构体 //
struct point
{
float x;
float y;
};
/*定义矩形结构体*/
struct rect
{
struct point pt1;
struct point pt2;
struct point pt3;
struct point pt4;
};
/*声明函数*/
float GetDis(struct point,struct point);
struct point makepoint(float x,float y);
//定义构造点函数//
struct point makepoint(float x,float y)
{
struct point temp;
temp.x=x;
temp.y=y;
return temp;
}
//定义构造矩形函数//
struct rect makerect(struct point pt1,struct point pt2,struct point pt3,struct point pt4,struct rect *screen)//struct rect *screen ?????//
{
(*screen).pt1=pt1;
(*screen).pt2=pt2;
(*screen).pt3=pt3;
(*screen).pt4=pt4;
}
//定义判断函数//
int PtRect(struct point p,struct rect r)
{
return p.x>=r.pt1.x && p.x<=r.pt3.x && p.y>=r.pt1.y && p.y<=r.pt3.y;
}
main()
{
struct point pt1=makepoint(0,0);
struct point pt2=makepoint(50,0);
struct point pt3=makepoint(50,10);
struct point pt4=makepoint(0,10);
struct rect screen;
makerect(pt1,pt2,pt3,pt4,&screen);//???????//
struct point middle=makepoint((screen.pt1.x+screen.pt2.x)/2,(screen.pt2.y+screen.pt4.y)/2);
printf("\n the middle point is(%f,%f)\n",middle.x,middle.y);
printf("%f\n",screen.pt1.x);
printf("%f\n",screen.pt1.y);
printf("%f\n",screen.pt2.x);
printf("%f\n",screen.pt2.y);
printf("%f\n",screen.pt3.x);
printf("%f\n",screen.pt3.y);
printf("%f\n",screen.pt4.x);
printf("%f\n",screen.pt4.y);
if (PtRect(middle,screen))
printf("the middle point is in screen!");
else
printf("the middle point is not in screen");
getchar();
getchar();
}
结构体在定义时和引用是格式为什么不一致,前面定义时是:
struct rect makerect(struct point pt1,struct point pt2,struct point pt3,struct point pt4,struct rect *screen)
后面引用时是:
makerect(pt1,pt2,pt3,pt4,&screen)
请问这是为什么?