So why we need to declared the type like : int check(int a) { … }
From this it is clear you’re referring to the function and not to the variable itself. That part of the code is defining a function.
So, let’s separate the two things in your code:
int (a);
Declares variable a
. As @eyl327 stated:
There is no difference between int (a); and int a;
So that int could be called whatever you wanted; that it now has the same name as the variable used in the function definition is just coincidence. It could be, for example, int my_integer;
.
int check(a) {
return a % 2;
}
Here you define a function which receives an integer and which will return modulo 2 of that int (you can read this if you don’t know what that means).
It is missing the type of the variable which receives the function. It should be, instead:
int check(int a) {
return a % 2;
}
Now, I think it is possible that the combination used in your code is valid, but I’ve never seen it before, and if you’re learning now, I’d suggest you get familiar with the traditional way of defining variables and functions.
Hope this helps!
1
solved Why should I wrap variable name inside parenthesis in C programming?