Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between these 2 declarations in c?

Tags:

c

syntax

typedef int (*P)(char *(*)());

int (*P)(char *(*)());

Both seems to be doing the same thing to me,what's the typedef there for?

like image 206
yoyo Avatar asked Dec 09 '22 12:12

yoyo


1 Answers

The first declares a type called P that you can use in the declaration of other variables. The second declares a variable of that same type.

For illustrative purposes:

typedef int (*P)(char *(*)());

int main() {
    int (*Q)(char *(*)());
    P R;
}

In this example the variables Q and R have exactly the same type.

like image 195
cdhowie Avatar answered Dec 12 '22 01:12

cdhowie