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?
Declaration of a variable in a computer programming language is a statement used to specify the variable name and its data type. Declaration tells the compiler about the existence of an entity in the program and its location. When you declare a variable, you should also initialize it.
For example, if the my_function() function, discussed in the previous section, requires two integer parameters, the declaration could be expressed as follows: return_type my_function(int x, y); where int x, y indicates that the function requires two parameters, both of which are integers.
For example: int age; float weight; char gender; In these examples, age, weight and gender are variables which are declared as integer data type, floating data type and character data type respectively.
Difference b/w variable declaration and definition: Variable declaration refers to the part where a variable is first declared or introduced before its first use. Declaration of variable type is also done in the part. A variable definition is a part where the variable is assigned a memory location and a value.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With