complicated declaration

Discussion in 'C Programming' started by asit, Mar 13, 2008.

  1. asit

    asit Guest

    Are the following declaration correct ??

    int *p// p is a pointer to integer

    int *p[]// p is an array of integer pointers

    int (*p)[]// p is a pointer to an integer array

    int *p()// p is a pointer to function returning
    address of an integer(integer pointer)

    int p(char *)//p is a function which takes a character pointer
    as an argument and returns an integer

    int *p(char *)// p is a function which takes a character pointer
    as an argument and returns the address of an integer(integer pointer)

    int (*p)(char *)// p is a pointer to a function which takes a
    character pointer
    as an argument and returns an integer

    ---------------------------------------------

    int (*p(char*))[]// p is a pointer to a function and takes a character
    pointer
    as an argument and returns an array of integers

    int p(char(*a)[])//p is a function which takes a pointer to a
    character array
    as an argument and returns an integer

    int p(char*[])//p is a function which takes an array of character
    pointers
    as an argument and returns an integer

    int *p(char a[])//p is a function which takes a character array
    as an argument and returns an address of an integer(integer pointer)

    int p(char (*a)[])//p is a function which takes a pointer to a
    character array
    as an argument and returns an integer

    int *p(char *a[])//p is a function which takes an array of character
    pointers
    as an argument and returns the address of an integer(integer pointer)

    int (*p)(char (*a)[])//p is a pointer to function which takes a
    pointer
    to a character array as an argument and returns an integer

    int *(*p)(char(*a)[])//p is a pointer to function which takes a
    pointer
    to a character array as an argument and returns the address of an
    integer(integer pointer)

    --------------------------------------------

    int *(*p)(char *a[])//p is a pointer to function which takes an array
    of character pointers
    as an argument and returns the address of an integer(integer pointer)

    int (*p[])(void)//p is an array of pointers to function taking no
    argument
    and returning an integer

    int (*p[])(char a)//p is an array of pointers to function taking a
    character argument
    and returning an integer

    int *(*p[])(char a)//p is an array of pointers to function taking a
    character argument
    and returning an address of integer(integer pointer)

    int *(*p[])(char *a)//p is an array of pointers to function taking a
    character array as

    argument and returning an address of integer(integer pointer)
     
    asit, Mar 13, 2008
    #1
    1. Advertising

  2. asit

    WANG Cong Guest

    On Wed, 12 Mar 2008 23:54:25 -0700,asit wrote:

    > Are the following declaration correct ??


    Yes, except the below one.

    <snip>

    >
    > int *p()// p is a pointer to function returning address of an
    > integer(integer pointer)


    This is wrong. p is a function instead of a function pointer.
    If you want it to be a pointer, you should:

    int (*p)();

    And note that it can take *any* arguments, the following statements
    are correct.

    int (*p)();
    int (*q)(int);
    int (*r)(void);
    p = q;
    p = r;


    --
    Hi, I'm a .signature virus, please copy/paste me to help me spread
    all over the world.
     
    WANG Cong, Mar 13, 2008
    #2
    1. Advertising

  3. asit

    John Bode Guest

    On Mar 13, 1:54 am, asit <> wrote:
    > Are the following declaration correct ??
    >


    [snip]

    > int *p()// p is a pointer to function returning
    > address of an integer(integer pointer)
    >


    Incorrect. p is a function returning a pointer to int. What you're
    thinking of is

    int *(*p)();

    [snip]

    > int (*p(char*))[]// p is a pointer to a function and takes a character
    > pointer
    > as an argument and returns an array of integers
    >


    Incorrect in that functions may not return array types (or other
    function types), although you clearly understand declarator syntax.
    You can return a pointer to an array:

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

    p is a pointer to a function taking a char* argument and returning a
    pointer to an array of int.

    [snip remainder]
     
    John Bode, Mar 13, 2008
    #3
  4. John Bode <> writes:

    > On Mar 13, 1:54 am, asit <> wrote:
    >> Are the following declaration correct ??

    <snip>
    >> int (*p(char*))[]// p is a pointer to a function and takes a character
    >> pointer
    >> as an argument and returns an array of integers
    >>

    >
    > Incorrect in that functions may not return array types (or other
    > function types), although you clearly understand declarator syntax.
    > You can return a pointer to an array:
    >
    > int (*(*p(char*)))[];
    >
    > p is a pointer to a function taking a char* argument and returning a
    > pointer to an array of int.


    ITYM int (*((*p)(char*)))[];

    In general, where the name in next to a "(" it declares a function,
    not a pointer to one.

    --
    Ben.
     
    Ben Bacarisse, Mar 13, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    969
  2. Alex Vinokur
    Replies:
    4
    Views:
    603
    Jonathan Turkanis
    Apr 5, 2004
  3. Ovidesvideo
    Replies:
    4
    Views:
    527
    Andrey Tarasevich
    Dec 10, 2004
  4. kelvSYC
    Replies:
    6
    Views:
    7,264
    Richard Herring
    May 17, 2005
  5. Tobias Oed
    Replies:
    3
    Views:
    428
    Jason
    Jul 12, 2003
Loading...

Share This Page