typedef关键字
来源:互联网 发布:淘宝促销在哪里设置 编辑:程序博客网 时间:2024/06/05 22:35
#include <stdio.h>void print1(int,int);void print2(int,int);/* typedef 用于给类型定义别名 typedef 原类型名称 别名 *///基本数据类型typedef int myInt;typedef myInt myInt2;//指针typedef char * String;//结构体/* 1. struct Student { String name; }; typedef struct Student Stu; 2.typedef struct Student { String name; } Stu; *///3.typedef struct{ String name;} Stu;//枚举/* 1.enum Sex { female, male }; typedef Sex Sex 2.typedef enum Sex { female, male }Sex; *///3.typedef enum{ female, male}Sex;//指向函数的指针typedef void (*FunP) (int ,int);//指向结构体的指针typedef Stu * StuP1;typedef struct{ String name;} *StuP2;int main(){ myInt i=1; myInt2 i2=2; printf("i=%d, i2=%d\n",i,i2); printf("------------------------------\n"); String a,b; a="stra"; b="strb"; printf("a=%s, b=%s\n",a,b); printf("------------------------------\n"); Stu s1,s2; s1.name="s1"; s2.name="s2"; printf("s1.name=%s, s2.name=%s\n",s1.name,s2.name); printf("------------------------------\n"); Sex sex1,sex2; sex1=male; sex2=female; printf("sex1=%d, sex2=%d\n",sex1,sex2); printf("------------------------------\n"); FunP p1,p2; p1=print1; p2=print2; p1(1,2); p2(1,2); printf("------------------------------\n"); StuP1 sp1=&s1; StuP2 sp2=&s2; (*sp1).name="sp1"; sp2->name="sp2"; printf("sp1.name=%s, sp2.name=%s\n",sp1->name,(*sp2).name); return 0;}void print1(int a,int b){ printf("a+b=%d\n",a+b);}void print2(int a,int b){ printf("a-b=%d\n",a-b);}
执行结果
i=1, i2=2------------------------------a=stra, b=strb------------------------------s1.name=s1, s2.name=s2------------------------------sex1=1, sex2=0------------------------------a+b=3a-b=-1------------------------------sp1.name=sp1, sp2.name=sp2
0 0
- 关键字typedef
- typedef关键字
- 关键字typedef
- typedef 关键字
- 关键字typedef
- typedef关键字
- typedef关键字
- typedef关键字
- typedef 关键字
- typedef关键字
- typedef关键字
- typedef和typename关键字
- typedef和typename关键字
- 搞定typedef 、const 关键字
- typedef和typename关键字
- typedef和typename关键字
- typename和typedef关键字
- typedef关键字详解
- HDU 1062 — Text Reverse
- 安卓学习第十三天:大文件的IO,字符流,处理流,内部类,匿名内部类,线程初步
- 第6题
- 校赛总结
- Count Primes Total Accepted: 831 Total Submissions: 6167
- typedef关键字
- Spring安全权限管理(Spring Security)
- 【连载】Java学习系列(004)——程序逻辑-2(分支和循环)
- C语言笔记之头文件与链接(二)
- 计算机是如何启动的?
- APP_FIELD.CLEAR_DEPENDENT_FIELDS
- template
- 博客中的理解程度
- 1、模板--------注册与登录_基于xml格式的存储