zoukankan      html  css  js  c++  java
  • Item 17. 函数与数组声明上的比较

    Item 17. Dealing with Function and Array Declarators

    函数与数组的声明能够放在一起来比较,是因为它们有相同的遭遇,同是天涯沦落人。

    ------------------------------------------------------------------
    1、两种函数声明
    例如:
     int *f1(); // 返回类型为int* 的函数
     int (*fp1)(); // 指向返回类型为int的函数之指针

    2、两种数组
    例如:
    const int N = 12;
    int *a1[N]; // 有N个int*的数组
    int (*ap1)[N]; // 指向有N个int的数组之指针

    3、推而广之
    int (**ap2)[N]; // ptr to ptr to array of N ints
    int *(*ap3)[N]; // ptr to array of N int *
    int (**const fp2)() = 0; // const ptr to ptr to func
    int *(*fp3)(); // ptr to func that returns int *

    4、当函数遇上数组的时候
    int (*afp2[N])(); // array of N ptr to func that returns int

    另一种写法
    typedef int (*FP)(); // ptr to func that returns int
    FP afp3[N]; // array of N FP, same type as afp2

    5、当引用和const出现后:
    int aFunc( double ); // func
    int (&rFunc)(double) = aFunc; // ref to func
    int (*const pFunc)(double) = aFunc; // const ptr to func

     

  • 相关阅读:
    Redis 启动与授权
    ssh客户端乱码
    centos修改oracle字符集
    netty 基础知识
    推送技术
    oracle 12C安装问题
    Labview学习之路(十三)常用快捷键积累
    Labview学习之路(十二)如何让图片做前面板背景
    UCOSIII(一)常用函数积累
    Keil出现错误
  • 原文地址:https://www.cnblogs.com/aiwz/p/6333242.html
Copyright © 2011-2022 走看看