C typedef的用法 结构体指针的用法

来源:互联网 发布:南昌seo外包 编辑:程序博客网 时间:2024/06/04 18:20

 头文件:

#include<stdio.h>#ifndef _MAIN_H_#define _MAIN_H_typedef struct{int port;double speed;double time;}*Handle;extern double getspeed(Handle hand);#endif

 

#include"main.h"double getspeed(Handle hand){return hand->speed;}

 

#include"main.h"int getport(Handle hand){return hand->port;}

 

#include "main.h"int main(int argc, char**argv){typedef int A,*B;A a=1;B b;*b=2;int c;c=a+(*b);printf("c = %d\n",c);Handle hand=(Handle)malloc(sizeof(Handle));hand->port=8000;hand->speed=1033.83884;hand->time=109.8348;printf("speed is %lf\n",getspeed(hand));printf("port is %d\n",getport(hand));}

 

 

输出结果:

c = 3

speed is 1033.838840

port is 8000

原创粉丝点击