简体   繁体   中英

Function on a variable declaration

I'm reading the C Programming Language (chapter 5), and I'm confused by this example:

int n, array[SIZE], getint(int *);

Why is this function call in here like that? Is this just some tricky example and invalid code?

It's not calling the function; it's declaring its prototype. It's equivalent to:

int n;
int array[SIZE];
int getint(int*);

Since the statement began with a type specifier, namely int, then it suggests declaration. Thus what follows is a bunch of comma separated list of identifiers.

n being a single int variable.

array being an array of int.

getint being a function that returns an int and has one parameter that is an int pointer. It is unnamed and that is not important because this is a function declaration/prototype.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM