博客
关于我
一招搞定“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 利用pyttsx3文字转语音
    查看>>
    python 利用已有Ner模型进行数据清洗合并
    查看>>
    python 到大数据开发工程师_如何成为一个大数据开发工程师?
    查看>>
    python 加密解密(base64, AES)
    查看>>
    Python 包管理器和 Node.js
    查看>>
    Python 单词字母顺序不变且所有倒排
    查看>>
    python 反射机制
    查看>>
    python 启动提示IDLE's subprocess didn't make conne...
    查看>>
    python 命令接口_实现“[命令][操作][参数]”样式的命令行接口?
    查看>>
    Python 和 OpenCV.如何检测图像中的所有(填充)圆形/圆形对象?
    查看>>
    Python 和 RabbitMQ - 聆听来自多个渠道的消费事件的最佳方式?
    查看>>
    python编辑器打不开_关于命令ride.py打不开RF,而是打开pycharm编辑器问题解决思路...
    查看>>
    python编译exe同时支持32位_第三周:同时管理64位和32位版本的Python,并用Pyinstaller打包成exe...
    查看>>
    Python 和Java 哪个更适合做自动化测试?
    查看>>
    Python编程:掌握高级语言程序设计。从零基础到精通,收藏这篇就够了!
    查看>>
    python 图片转ico
    查看>>
    python 图片转文字、语音转文字、文字转语音保存音频并朗读
    查看>>
    python 在包含类似字符\x16、\x12、\x某某的数组中将以\x开头的字符找出来的方法
    查看>>
    Python 在并行进程之间共享字典
    查看>>
    Python 垃圾收集器文档
    查看>>