Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem of declaration in C language (http://www.go4expert.com/forums/declaration-c-language-t28043/)

wdliming 17Mar2012 15:35

Problem of declaration in C language
 
Today ,I have read the
<Expert C Programming,Deep C Secrets>,
Chapter 3.Unscrambling Declarations in C.
The author introduce the declaration of a little complicated function,then he left another exercise:
Code:

char *(*(c[10]))(int **p);
the answer is given at the of the Chapter 3

However, I am uncertain about the "c[10]",
the book is said:"c is an array[0...9] of pointer to a function returning a pointer-to-char",
I am thinking...
Is there a 10 function pointers ?
Could some master give me a example to show how to use the
char *(*(c[10]))(int **p);
in a C Program?
Thank you very much!

PieterBeyens 20Mar2012 17:08

Re: Problem of declaration in C language
 
Something like this?

Code:

#include <stdio.h>

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

char strf0[] = "function0";

char *f0(int **p)
{
        (void) p;
        return strf0;
}

int main(int argc, char** argv){
        c[0] = f0;
        printf("%s\n",f0(0));
        return 0;
}

Pieter Beyens
Bytelead

Scripting 21Mar2012 00:09

Re: Problem of declaration in C language
 
Quote:

Originally Posted by PieterBeyens (Post 93581)
Something like this?

Code:

#include <stdio.h>

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

char strf0[] = "function0";

char *f0(int **p)
{
    (void) p;
    return strf0;
}

int main(int argc, char** argv){
    c[0] = f0;
    printf("%s\n",f0(0));
    return 0;
}

Pieter Beyens
Bytelead

Yea, nice example.


All times are GMT +5.5. The time now is 17:10.