C语言学习入门 (九) typedef 关键字
来源:互联网 发布:oracle sql截取字符串 编辑:程序博客网 时间:2024/05/22 11:58
关键字:typedef
用法:为各种数据类型定义一个新名字(别名)
typedef与基本数据类型
typedef int Integer;Integer a= 8;
也可以在别名的基础上再起一个别名
typedef Integer MyInteger;MyInteger a = 8;
原来的数据类型也可以正常使用
typedef与指针
typedef char *String;String str = “jackie”;
typedef与结构体
typedefstructPerson Per;// 这样在定义结构体变量时 就不用带上struct 关键字了
Per p; p.name = “xyz”;
定义并取别名:
typedefstruct Student// 结构体名 Student 可以省略
{
int age;
} Stu;
void processStudent()
{
Stu student = {18};
student.age =19;
}
typedef与指向结构体的指针
typedef struct
{
int age;
} Stu;
Stu stu = {20};
typedef Stu *S;//指向结构体的指针 取别名 S
S s = &stu;
typedef struct LNode
{
int data;
struct LNode *next;
} LinkList, *SList;
int main(int argc, const char * argv[])
{
LinkList l = {1, NULL};
LinkList ll = {2, NULL};
l.next = ≪
printf("%d, ", l.next->data);
SList sl = ≪
if (sl->next != NULL)
printf("%d, ", sl->data);
return 0;
}
typedef与枚举类型
typedef enum
{
…
} Season;
//用法与结构体类似
typedef与指向函数的指针
int sum(int a, int b)
{
return a + b;
}
void main()
{
typedef int (*P)(int a, int b);
P p = sum;
int result = (*p)(3, 5);
return 0;
}
typedef与#define
typedef char *String;
String s = “abc”
#define String char *;
String s = “abc”; //这样使用效果一样
当 这样使用:
String s1,s2; //用第一种替换: char *s1, char *s2;
String s3,s4; //用第二种替换: char * s3, s4; <==> char *s3, char s4;
- C语言学习入门 (九) typedef 关键字
- C语言学习入门 (八) typedef 关键字
- C语言再学习 -- 关键字typedef
- C语言typedef 关键字
- C语言 - typedef关键字
- C语言--typedef关键字
- C语言关键字--- enum typedef
- C语言typedef关键字总结
- C语言的 typedef 关键字
- C语言之关键字typedef
- 【C语言学习笔记】关键字:typedef、static和extern
- C语言中的typedef关键字的使用
- C语言的关键字typedef的用法
- 16、黑马程序员-C语言typedef关键字
- C语言-关键字typedef的使用
- C语言关键字之typedef的使用
- C语言中typedef关键字的作用
- C语言学习之typedef
- Java加密技术(一)——BASE64与单向加密算法MD5&SHA&MAC
- OJ刷题之分数序列
- wireshark error: There are no interfaces on which a capture can be done.
- MFC中获得系统时间的方法
- 多项式加法
- C语言学习入门 (九) typedef 关键字
- [leetcode]Binary Tree Preorder Traversal
- 再探扩展欧几里得算法的应用
- Java关键字this、super使用总结
- MySQL存储过程
- Unity的Profiler性能分析
- 复习设计模式
- JAD反编译
- 数字小写转大写