博客
关于我
一招搞定“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/

    你可能感兴趣的文章
    php布尔值的++
    查看>>
    PHP常量、变量作用域详解(一)
    查看>>
    PHP应用目录结构设计
    查看>>
    PHP应用程序连接MSQL数据库Demo(附crud程序)
    查看>>
    PHP应用程序连接Oracle数据库Demo(附Oracle客户端安装文件)
    查看>>
    PHP开发api接口安全验证
    查看>>
    PHP开发规范PSR
    查看>>
    PHP开发遇到错误0001
    查看>>
    rabbitmq guestguest用户不能远程登录
    查看>>
    php异常处理
    查看>>
    PHP引入了泛型和集合两大重要特性,大大改善 PHP 代码的可维护性和可读性
    查看>>
    PHP引擎php.ini参数优化
    查看>>
    PHP引用(&)使用详解
    查看>>
    php引用及垃圾回收
    查看>>
    php当前时间的集中写法
    查看>>
    php循环比较数组中的值,如何从PHP数组中计算值并在foreach循环中仅显示一次值?...
    查看>>
    php微信 开发笔记,微信WebApp开发总结笔记
    查看>>
    php微信公众号开发access_token获取
    查看>>
    php微信公众号开发微信认证开发者
    查看>>
    php微信公众号开发用户基本信息
    查看>>