Char (*(*x())[]) ()

This looks like an evil example straight from the 2nd edition of Kernighan and Ritchie (The C Programming Language), p. 122 (section 5.12: Complicated Declarations), where it is described as a function returning a pointer to an array of pointers to functions returning char. Here is a usage example:

#include <stdio.h>

char x1() { return 'a'; } // Function returning a char-----1
char (*x2[])() = {&x1}; // Array of pointers to functions returning char------2


char (*(*x())[])() { return &x2; } // Function returning a pointer to the above----3

// 分析:将*x()看做一个整体==XX,则上式等价于char (*XX[])() ,这样3式就转化为2式,只是XX为函数指针

// so:x是一个函数,它返回一个指针,该指针指向一个一维数组,该一维数组的元素为指针,这些指针分别指向函数,这些函数的返回值维char类型

void main()
{
    char (*x3)() = **x(); // Pointer to a function returning char
    printf("This is the value: %c\n", x3());
}

Alternatively, you could skip declaring x3 altogether and just write

printf("This is the value: %c\n", ((*(x()))[0])());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值