C语言的typedef用法
生活随笔
收集整理的這篇文章主要介紹了
C语言的typedef用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
案例1:?
#include <stdio.h> #include <string.h> #include <malloc.h>typedef int zhangsan; //為int在多取一個名字 zhangsan等價于intstruct Student{int sid;char sname[100];char sex;} ST;int main() {int i = 10; //等價于zhangsan i=10zhangsan j = 20;printf("%d", j);char c = '\0';printf("%c\n", c);printf("c輸出得:%d\n", (int)c);struct Student st;struct Student * ps = &st;ST.sid=12;ST.sex = 'n';strcpy_s(ST.sname , "lisi");printf("%c\n", ST.sex);printf("%d\n", ST.sid);printf("%s\n", ST.sname);while (true){}return 0; }?
案例2:
#include <stdio.h> #include <string.h> #include <malloc.h>typedef int zhangsan; //為int在多取一個名字 zhangsan等價于inttypedef struct Student{int sid;char sname[100];char sex;} ST;int main() {int i = 10; //等價于zhangsan i=10zhangsan j = 20;printf("%d", j);char a = '\0';printf("%c\n", a);struct Student st;struct Student * ps = &st;ST st2; //等價于 struct Student st;st2.sid = 12;st2.sex = 'n';strcpy_s(st2.sname, "lisi");printf("%c\n", st2.sex);printf("%d\n", st2.sid);printf("%s\n", st2.sname);while (true) {}return 0; }?案例3:
#include <stdio.h> #include <string.h> #include <malloc.h>typedef int zhangsan; //為int在多取一個名字 zhangsan等價于inttypedef struct Student{int sid;char sname[100];char sex;} * PST; //等價于struct Student * int main(void) {struct Student st;PST ps = &st;ps->sid = 99;printf("%d\n", ps->sid);while (true) {}return 0; }?
案例4:
#include <stdio.h> #include <string.h> #include <malloc.h>typedef int zhangsan; //為int在多取一個名字 zhangsan等價于inttypedef struct Student {int sid;char sname[100];char sex;} *PSTU,STU; //PSTU等價于struct Student * (PSTU表示結構體指針),STU等價于struct Student st (結構體本身)int main(void) {STU st;PSTU ps = &st;ps->sid = 99;printf("%d\n", ps->sid);while (true) {}return 0; }?
總結
以上是生活随笔為你收集整理的C语言的typedef用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python有限循环_Python循环
- 下一篇: web开发常用工具介绍