博客
关于我
一招搞定“C语言声明式”类型的面试题
阅读量:121 次
发布时间:2019-02-26

本文共 3104 字,大约阅读时间需要 10 分钟。

C????????????????????????????????????????????????C??????????????????

C?????????

C?????????????????????????????????????????????????????????????????????????????????????????

  • ??????

    • ????????????
    • ??*?????
    • const?volatile???????????int?long????????????????????
  • ?????

    • ?????????????
    • ????????????????
    • ????????????
    • ????const?volatile???????????
  • ?????????

    ??1?char * const * p;

    • ?????
    • p???????????
    • ???????????char??????
    • p??????????????????

    ??2?char (* c[10])(int **p);

    • ?????
    • c?????10???????
    • ?????????????????????????????
    • ???????int????????char???

    ??????

    ????????????????????????????cdecl.c????C????????????????????????????????????

    ?????

    #include 
    #include
    #include
    #include
    #define MAXTOKENS 100#define MAXTOKENLEN 64enum type_tag { IDENTIFIER, QUALIFIER, TYPE };struct token { char type; char string[MAXTOKENLEN]; };int top = -1;struct token stack[MAXTOKENS];struct token this;#define pop stack[--top]#define push(s) stack[++top] = svoid gettoken() { char *s = this.string; while ((*s = getchar()) == ' ') { if (feof(stdin)) { *s = '\0'; break; } } if (isalnum(*s)) { push(this); while (isalnum(*s = getchar())) { *s = '\0'; } ungetc(*s, stdin); this.type = classify_string(); return; } if (*s == '*') { strcpy(this.string, "pointer to"); this.type = '*'; return; } this.string[1] = '\0'; this.type = *s; return;}void read_to_first_identifier() { gettoken(); while (this.type != IDENTIFIER) { push(this); gettoken(); } printf("%s is ", this.string); gettoken();}void deal_with_arrays() { while (this.type == '[') { printf("array "); gettoken(); if (isdigit(this.string[0])) { printf("0..%d ", atoi(this.string) - 1); gettoken(); } gettoken(); printf("of "); }}void deal_with_function_args() { while (this.type != ')') { gettoken(); } gettoken(); printf("function returning ");}void deal_with_pointers() { while (stack[top].type == '*') { printf("%s ", pop.string); }}void deal_with_declarator() { switch (this.type) { case '[': deal_with_arrays(); break; case '(': deal_with_function_args(); break; } deal_with_pointers(); while (top > 0) { if (stack[top].type == '(') { pop; gettoken(); deal_with_declarator(); } else { printf("%s ", pop.string); } }}int main() { read_to_first_identifier(); deal_with_declarator(); printf("\n"); return 0;}

    ????

    ?????????????????

    char * const * p;char (* c[10])(int **p);

    ???????????

    p is pointer to function returning pointer to charc is array of 10 pointers to function returning pointer to char, function takes pointer to pointer to int and returns pointer to char

    ??

    ???????????????????????????C????????????????????????????????C?????????????????????????????????????????????????????

    ????????????????Expert C Programming??????????????????????????????????????????????????????

    转载地址:http://ldqu.baihongyu.com/

    你可能感兴趣的文章
    python系列【仅供参考】:python之subprocess模块rsync拉取文件
    查看>>
    python系列【仅供参考】:python 远程rdp
    查看>>
    python基础
    查看>>
    Python基本语法与变量类型
    查看>>
    python基本数据类型(容器)- tuple list dict set
    查看>>
    python基本工资的调整方案_Python薪资又涨了!这可咋办!
    查看>>
    Python基准测试和性能分析内存管理和垃圾回收
    查看>>
    Python基于RESTful风格的接口自动化测试实战
    查看>>
    python基于pygame实现跨年烟花效果
    查看>>
    python基于flask搭建http服务(四)—— Docker容器化部署
    查看>>
    python基于flask搭建http服务(二)—— 实现Excel上传、数据清洗、入库
    查看>>
    python基于flask搭建http服务(三)—— 使用gunicorn部署项目
    查看>>
    python基于flask搭建http服务(一)—— 实现数据查询和Excel导出
    查看>>
    Python块键盘/鼠标输入
    查看>>
    Python在正确的时区获取当前时间
    查看>>
    python在心理学研究中的应用有哪些_心理学在线研究可用平台简介和应用进展
    查看>>
    python系列【仅供参考】:python tornado 集成redis消息订阅的异步任务之后tornado主程序无法启动,解决方案
    查看>>
    Python在列表理解中使用枚举
    查看>>
    python在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>...
    查看>>
    python在gpu上运行_【python】python开启GPU加速
    查看>>