1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Problem of declaration in C language

Discussion in 'C' started by wdliming, Mar 17, 2012.

  1. wdliming

    wdliming New Member

    Joined:
    Sep 26, 2010
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    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!
     
    Last edited by a moderator: Mar 17, 2012
  2. PieterBeyens

    PieterBeyens New Member

    Joined:
    Mar 19, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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
     
  3. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Yea, nice example.
     

Share This Page