struct hypot typedef

来源:互联网 发布:windows outlook 编辑:程序博客网 时间:2024/05/21 20:21

C语言定义结构体:struct 结构体名称{域定义};

但是为了使用方便用:typedef struct {域定义};结构体名称;

示例:

#include<stdio.h>#include<math.h>struct Point{double x,y;};double dist(struct Point a,struct Point b){    return hypot(a.x - b.x,a.y - b.y);}int main(){    Point a,b;    a.x = 1,a.y = 1;    b.x = 2,b.y = 2;    double c = dist(a,b);    printf("%lf\n",c);    return 0;}

#include<stdio.h>#include<math.h>typedef struct {double x,y;}Point; //多了typedef,可以像int ,double,float用double dist(Point a,Point b)       //少了struct{    return hypot(a.x - b.x,a.y - b.y);}int main(){    Point a,b;    a.x = 1,a.y = 1;    b.x = 2,b.y = 2;    double c = dist(a,b);    printf("%lf\n",c); //输出1.414214    return 0;}


0 0
原创粉丝点击