What do "int *p(char *a)" & "char (*p)(int *a)" mean?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • staz

    #1

    What do "int *p(char *a)" & "char (*p)(int *a)" mean?

    I cant recognise them as declarations of some arrays or so... Are they some declaration of functions with parameter & return type? If so, then how come function names are missing?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    "int *p(char *a)" & "char (*p)(int *a)" mean?

    This code is written to trip you up since beginners think "p" means "pointer". Because of that assumption, you can't read this code.

    Code:
    int *p(char *a)
    is a function named "p" that takes a char* argument "a" and returns a pointer to an int. You would have no problem were it written like this:

    Code:
    int *MyFunction(char *arg)
    This one:

    Code:
    char (*p)(int *a)
    defines "p" to be a pointer to a function that takes an int* arguments "a" and returns a char.

    I expect I am doing your homework, but at least now you know.

    Comment

    Working...